Click here to Skip to main content
15,789,700 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionASP.Net MVC: How to print raw model in razor view Pin
Mou_kol24-Dec-19 23:19
Mou_kol24-Dec-19 23:19 
AnswerRe: ASP.Net MVC: How to print raw model in razor view Pin
F-ES Sitecore25-Dec-19 10:17
professionalF-ES Sitecore25-Dec-19 10:17 
QuestionallowDefinition='MachineToApplication' beyond application level Pin
kuldeeps2117-Dec-19 5:53
kuldeeps2117-Dec-19 5:53 
AnswerRe: allowDefinition='MachineToApplication' beyond application level Pin
Richard Deeming17-Dec-19 6:07
mveRichard Deeming17-Dec-19 6:07 
QuestionScrape with htmlagilitypack problems Pin
Member 175325016-Dec-19 7:02
Member 175325016-Dec-19 7:02 
AnswerRe: Scrape with htmlagilitypack problems Pin
Richard Deeming16-Dec-19 9:41
mveRichard Deeming16-Dec-19 9:41 
GeneralRe: Scrape with htmlagilitypack problems Pin
Member 175325018-Dec-19 12:22
Member 175325018-Dec-19 12:22 
QuestionASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Mou_kol15-Dec-19 10:33
Mou_kol15-Dec-19 10:33 
I am sending list of data from action to client side. in client side i am binding jquery data table with pass data. column name is extracted because column is dynamic in my case. i got a below code which is not very clear how it is working.

My question is very basic question. see how list of data is pass from action to client side.
C#
[HttpGet]
public ActionResult Index()
{

    List<UserData> data = new List<UserData>
    {
    new UserData
    {
    ID = 1,
    Name = "Simon"
    },
    new UserData
    {
    ID = 2,
    Name = "Alex"
    }
    };

    return View(data);
}


passed model data is captured like below way which is not clear to me
C#
var keys = Object.keys(@Html.Raw(Json.Encode(Model[0])));
    var columns = keys.map(function (key) {
    return { title: key };
});

var data = @Html.Raw(Json.Encode(Model));
    var dataSet = data.map(function (d) {
    return Object.values(d);
});

console.log(columns);
console.log(dataSet);


see this code first
C#
var keys = Object.keys(@Html.Raw(Json.Encode(Model[0])));
    var columns = keys.map(function (key) {
    return { title: key };
});


1) we know list is kind of array then why keys are extracted from zeroth position ? Model[0] why not Model[1]

i like to know in what form data is stored into model when pass from action to client side ?
see this code again
C#
var data = @Html.Raw(Json.Encode(Model));
    var dataSet = data.map(function (d) {
    return Object.values(d);
});


2) in above code no ordinal position mention during extracting data. why?

3) what is Model[0] ? how it comes? because in asp.net mvc we write model like @model not Model

4) is this Model is Asp.Net MVC related model or javascript Model object ?

During keys extraction ordinal position is mentioned but in case of data extraction no ordinal position mentioned. please explain if some one understand what i am trying to know.

My main question is i have only one question that what is Model[0] here in js? is it any JavaScript related object or server side object ? if it is javascript then how server side model data comes into js model ?

please explain how above code is working at client side. thanks
AnswerRe: ASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Richard Deeming16-Dec-19 9:30
mveRichard Deeming16-Dec-19 9:30 
GeneralRe: ASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Mou_kol24-Dec-19 22:14
Mou_kol24-Dec-19 22:14 
GeneralRe: ASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Richard Deeming7-Jan-20 9:09
mveRichard Deeming7-Jan-20 9:09 
QuestionHow do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 22:39
Marc Hede12-Dec-19 22:39 
AnswerRe: How do I change this code using Inheritance? Pin
Richard MacCutchan12-Dec-19 23:15
mveRichard MacCutchan12-Dec-19 23:15 
AnswerRe: How do I change this code using Inheritance? Pin
phil.o12-Dec-19 23:23
professionalphil.o12-Dec-19 23:23 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 23:57
Marc Hede12-Dec-19 23:57 
GeneralRe: How do I change this code using Inheritance? Pin
phil.o13-Dec-19 0:26
professionalphil.o13-Dec-19 0:26 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 0:49
Marc Hede13-Dec-19 0:49 
GeneralRe: How do I change this code using Inheritance? Pin
F-ES Sitecore13-Dec-19 0:59
professionalF-ES Sitecore13-Dec-19 0:59 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 1:17
Marc Hede13-Dec-19 1:17 
GeneralRe: How do I change this code using Inheritance? Pin
phil.o13-Dec-19 1:52
professionalphil.o13-Dec-19 1:52 
GeneralRe: How do I change this code using Inheritance? Pin
F-ES Sitecore13-Dec-19 1:54
professionalF-ES Sitecore13-Dec-19 1:54 
GeneralRe: How do I change this code using Inheritance? Pin
Richard Deeming13-Dec-19 1:58
mveRichard Deeming13-Dec-19 1:58 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 1:00
mveRichard MacCutchan13-Dec-19 1:00 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 1:25
Marc Hede13-Dec-19 1:25 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 1:44
mveRichard MacCutchan13-Dec-19 1:44 

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.