jquery - Alternative to observablecollection in asp.net mvc -


i had wpf application, used observablecollection refresh/change/add view viewmodel of binding.

now im having additional requirement create web application using asp.net mvc

is there alternative observablecollection in asp.net mvc?

if , give example jquery , razor engine(asp.net mvc)..

no there isn't. thing events not used in sense in web development. closest thing observable collections requesting lists in json server ajax , render data clientside. clever use of generics, reflections , javascript perhaps turn code more dynamic.

simple example:

controller:

public jsonresult getpersons() {       var list = new list<string> { "jake", "jenny", "joe" };       return json(list, jsonrequestbehavior.allowget); } 

html:

<ul id='personlist'></ul> 

jquery:

    $.getjson('@url.action("getpersons", "mycontroller")',null,             function (data) {                 // iterate each person requested data                 $.each(data, function (i, p) {                      // render each person li                     $("#personlist").append('<li>'+p+'</li>');                 });             }); 

another, not dynamic solution requesting view, using viewmodel list of persons in it.

public class personsviewmodel {     public list<string> persons { get; set; }      public personsviewmodel(list<string> persons)     {         persons = persons;     } }  public actionresult persons() {       var list = new list<string> { "jake", "jenny", "joe" };       return view(new personsviewmodel(list)); } 

view:

<ul>     @foreach (var item in model.persons)     {       <li>@item.tostring()</li>     } </ul> 

if newbie asp.net mvc , been doing wpf/winforms before tip forget knew events.


Comments