Partial Views vs. Json (or both)

I use ASP.NET MVC with jQuery and have a lot of Ajax requests to my controllers. Use Partial Views (usercontrols) to build the intial view when a page is loaded. Then if I need to append/replace data based on my Ajax request I build HTML from the Json response. This approach gives me full control, ie. I can get extra information back from my controller if something went wrong, and then show an error message based on that. However, recently I've been really annoyed with all the extra work that goes into maintaining HTML structure both in my partial views and the part that generates HTML from Json. I like to make a jQuery ajax request and then have the controller return PartialView("mypartialview") and then just use jQuery to replace to HTML in the view. However, this way I cannot attach extra data from the controller - it's either whatever the partial view gives me - or nothing. At least that's my current take on it. If some validation goes wrong at some point in my controller action I don't want to return the HTML of the partial view. So how do you go about handling this issue? Thanks for reading.

以上就是Partial Views vs. Json (or both)的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准