0

I am making an ajax call to controller to post data from view to controller.And in the receiving controller I am updating my model with new values.Now I want to bind this new model to view again in success call of $.ajax post.Please Suggest.

Sameer More
  • 589
  • 1
  • 6
  • 13

2 Answers2

0

one way to do this is to return a partial view from the controller. You can replace the contents of your previous view with the new html content. Lets expand on this...

so, here is your controller action

  [HttpPost]
  public ActionResult SomeMethod(params...){
      ....
      var model = some model;
      ...
      return PartialView("ViewName",model);
  }

and in the ajax, use

$.ajax({
   url : @Url.Create("Action","Controller"),
   type : 'POST',
   data: { ... your data params ..}, 
   success : function(result){
       $("#ContainerId").html(result);
   }
})

in the html you would need a div with the id = "ContainerId". The content would get swapped out by the html passed back in the success function.

monkeyhouse
  • 2,875
  • 3
  • 27
  • 42
  • also see http://stackoverflow.com/questions/10431181/how-to-call-partial-view-through-ajax-in-mvc3 for another example – monkeyhouse Jun 28 '13 at 23:17
0

The Model is only used in RAZOR when rendering the page. Once you get to the point where you are using AJAX, the model is no longer available to you.

What, exactly, are you trying to accomplish? Maybe there is another way to do it?

Scottie
  • 11,050
  • 19
  • 68
  • 109