Click here to Skip to main content
15,878,959 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: ASP.Net MVC: How to print raw model in razor view Pin
F-ES Sitecore25-Dec-19 9:17
professionalF-ES Sitecore25-Dec-19 9:17 
QuestionallowDefinition='MachineToApplication' beyond application level Pin
kuldeeps2117-Dec-19 4:53
kuldeeps2117-Dec-19 4:53 
AnswerRe: allowDefinition='MachineToApplication' beyond application level Pin
Richard Deeming17-Dec-19 5:07
mveRichard Deeming17-Dec-19 5:07 
QuestionScrape with htmlagilitypack problems Pin
Member 175325016-Dec-19 6:02
Member 175325016-Dec-19 6:02 
AnswerRe: Scrape with htmlagilitypack problems Pin
Richard Deeming16-Dec-19 8:41
mveRichard Deeming16-Dec-19 8:41 
GeneralRe: Scrape with htmlagilitypack problems Pin
Member 175325018-Dec-19 11:22
Member 175325018-Dec-19 11:22 
QuestionASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Mou_kol15-Dec-19 9:33
Mou_kol15-Dec-19 9:33 
AnswerRe: ASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Richard Deeming16-Dec-19 8:30
mveRichard Deeming16-Dec-19 8:30 
Both @Html.Raw(Json.Encode(Model[0])) and @Html.Raw(Json.Encode(Model)) are evaluated on the server. The Model refers to the server-side model of the view.

Not to be confused with the @model directive, which declares the type of the model for the view. @model declares the type; Model refers to the instance of that type.

@Html.Raw(Json.Encode(Model[0])) will generate a Javascript object representing the first item in the list. You specify the index because you only need the keys from one item. You don't use Model[1] in case there isn't a second item in the list.

For example, the rendered Javascript will look something like:
JavaScript
var keys = Object.keys({ "ID": 1, "Name": "Simon" });
NB: If the list is empty, you will get an exception when ASP.NET tries to evaluate the view to generate this code.

@Html.Raw(Json.Encode(Model)) will generate a Javascript array containing all of the items from the list. For example:
JavaScript
var data = [
    { "ID": 1, "Name": "Simon" },
    { "ID": 2, "Name": "Alex" }
];




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: ASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Mou_kol24-Dec-19 21:14
Mou_kol24-Dec-19 21:14 
GeneralRe: ASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Richard Deeming7-Jan-20 8:09
mveRichard Deeming7-Jan-20 8:09 
QuestionHow do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 21:39
Marc Hede12-Dec-19 21:39 
AnswerRe: How do I change this code using Inheritance? Pin
Richard MacCutchan12-Dec-19 22:15
mveRichard MacCutchan12-Dec-19 22:15 
AnswerRe: How do I change this code using Inheritance? Pin
phil.o12-Dec-19 22:23
professionalphil.o12-Dec-19 22:23 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 22:57
Marc Hede12-Dec-19 22:57 
GeneralRe: How do I change this code using Inheritance? Pin
phil.o12-Dec-19 23:26
professionalphil.o12-Dec-19 23:26 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 23:49
Marc Hede12-Dec-19 23:49 
GeneralRe: How do I change this code using Inheritance? Pin
F-ES Sitecore12-Dec-19 23:59
professionalF-ES Sitecore12-Dec-19 23:59 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 0:17
Marc Hede13-Dec-19 0:17 
GeneralRe: How do I change this code using Inheritance? Pin
phil.o13-Dec-19 0:52
professionalphil.o13-Dec-19 0:52 
GeneralRe: How do I change this code using Inheritance? Pin
F-ES Sitecore13-Dec-19 0:54
professionalF-ES Sitecore13-Dec-19 0:54 
GeneralRe: How do I change this code using Inheritance? Pin
Richard Deeming13-Dec-19 0:58
mveRichard Deeming13-Dec-19 0:58 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 0:00
mveRichard MacCutchan13-Dec-19 0:00 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 0:25
Marc Hede13-Dec-19 0:25 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 0:44
mveRichard MacCutchan13-Dec-19 0:44 
QuestionHistogram in Asp.net using canvas js Pin
pooja thombare11-Dec-19 20:47
pooja thombare11-Dec-19 20:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.