0

I'm trying to solve a problem. I am new to MVC and trying to understand how the models work. I get the main page and main model stuff and that if you want to show a partial view the data you show must be part of the main model. This makes the main model pretty large and doesn't that require me to submit the entire model to get the partial view? In any case, let's say I have a list of things and one column is a link. This link calls an AJAX method to get more data and display in a jQuery dialog - my goal. So I would have a call like this:

 function showDetails(id) {
     $("#divShowDetails").load('@(Url.Action("GetDetails", "Home", null, Request.Url.Scheme))?Id= ' + id);
  }

My view is like "_DetailsView.cshtml", defined as a partial view. Does this page need to define the model in the main page or can it be a different model or no model at all? Can I return a ViewData from the controller method, pop open the dialog and fill it with data?

Should the controller method return a PartialViewResult or just an ActionResult? Let's say the details view are details of a part number or something and I want to show a bunch of data elements for the part. Does this have to me a model? I am confused and any help would be greatly appreciated.

Thanks guys. Do you still use the common:

 [HttpGet]
 public PartialViewResult SelectedItem (string itemId)
 {
     // gather data for the item
     return PartialView(itemModel);
  }

And you are saying that the itemModel does not have to be part of the item list model?

2
  • if you use an ajax call you won't need to send the partial model through the main model. look at the question here stackoverflow.com/questions/19592344/… for an example Commented Oct 8, 2014 at 13:41
  • A partial can view can contain a model of any kind no matter what the model is in the main view. This is one of the many advantages of using partial views, you can render whatever model you need on any page Commented Oct 8, 2014 at 18:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.