asp.net mvc - Rendering view using ViewModel or JSON object -


my searching failed find thought travelled subject. options outlined @ bottom reflect things found.

i need render view server side viewmodel or via json object. json object come server.

on client side use ajax , determine insertion based on other id/attributes on page whether append/prepend/replace or ignore-placing target element.

what options have use same view viewmodels or json objects?

i had considered, on compile, render file.js version of view. include resource on page , perform replaces on var viewhtmltemplate = "<div>@model.message</div>. have disciplined in moving formatting/if-statement logic viewmodel json serialized.

or, view has script tag bind viewmodel serilized js var , run function on document ready.

the 3rd option instead of returning json object, return array of serverside html-rendered views.

what inside of view model have field string serialized json structure.

public class somevm {  /* other properties */  public string jsonstring { get; set; } } 

in controller serialize data jsonstring. in view, assign string variable

@model somevm <script>  var jsonvm = @( html.raw(model.jsonstring) ); </script> 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -