I have an MVC3 application that I am implementing pjax into . Everything is working well except what to do on the server side when an address gets loaded that doesn’t already have the main view on the client side. My Controller code looks like
public virtual ActionResult Details(Guid id)
{
var partDetail = new PartDetail(id);
var partialView = PartialView("Details", partDetail);
if(Request.Headers["X-PJAX"]!= null)
{
return partialView;
}
var mainView = View("Index");
// Stick Partial View into main view at #update_panel?
return mainView;
}
How can I stick the partial View into the main view so it inserts the partial view in the #update_panel?
Ok, without a major refactor, you could do the following.
(this assumes that you are able to set the
@modelon index.cshtml toPartDetail()).in your controller action above, change:
to:
then, inside your index.cshtml, add the following:
As i said, this will ONLY work if the index @model is set to
PartDetail(), otherwise, a little refactoring on the model in the index view will be required to include thisPartDetail()model. this viewmodel might well look like the following:this refactored viewmodel would be added to the index.cshtml as
@model IndexViewModeland consumed by the partial as:hope this makes sense.