Looking for recommendation on posting back data (in ASP.NET MVC) for data parsed in client (using javascript)
I have a textarea on my webpage which will get its value parsed and put into a preview. I want the parsed into to get sent back via postback and I'm looking for some feedback on how the best way to do this.
For more details on what's in my tex开发者_Python百科t area, basically, it's a large textarea and inside people are going to enter sections which contains lines. My javascript parsing will infer where the sections being and end. On postback, I'd like to send something like an array of sections which contains an array of lines.
Should I stick json into hidden field? Should I create multiple hidden fields for each section or line?
This is what I'm trying to bind in my controller:
public class SheetViewModel
{
public int SheetID { get; set; }
public string Key { get; set; }
public List<SectionViewModel> Sections { get; set; }
}
public class SectionViewModel
{
public int Number { get; set; }
public string SectionType { get; set; }
}
I would use AJAX in that case (and probably use jQuery.post() on the client side). No need for hidden fields - and certainly no need for postbacks either.
Edit - just to make the above italics clearer:
- MVC has posts, not (necessarily) postbacks.
- Please notice that the traditional postback model is flawed. So no need to emulate it in ASP.NET MVC...
精彩评论