I'm using ASP.NET MVC 3. I have a question if it's possible to update the model, even if it's not being sent to the controller? Perhaps the question is completle of, or I'm doing things in a wrong way?
I have an ajax-call to a controller method. I'm passing in an id. I would like the controller to find some stuff in the db, and then update the model, passing it back to the view.
I've got a pretty big model... I've found some solutions, where to convert the model to a javascript object, and send it to the controller. Is that the only/right way?
How to send a model in jQuery $.ajax() post request to MVC controller method
I thought that maybe the controller has the model, where I could update some fields in it?
The call to the controller:
function getBis(id) {
$.ajax({
type: "GET",
url: '@Url.Action("GetBis")',
data: { "id": id },
dataType: 'json',
cache: false,
success: function (data) {
// Do something here
},
error: function (jqXHR, textStatus, errorThrown) {
alert("Problem!");
}
});
}
The controller code:
public ActionResult GetBis(string id)
{
BeslutIStortDTO viewModel = new BeslutIStortDTO();
int theId;
if (!Int32.TryParse(id, out theId))
throw new Exception("Wrong id");
viewModel = _blLayer.GetBIS(theId);
// somehow update the model here!
return View("index", viewModel);
}