The overload for @Html.Partial takes a model, so in the “primary” view I put in this.model:
@Html.Partial("_GenericIndex", this.Model )
I tried just putting @Model in the partial view to see if anything showed up, but I got nothing.
So, how do I use that this.Model parameter in the partial view? I have seen some horrible solutions where it was prepared especially for the partial view in viewdata or something. Surely that is not necessary?
I just want to access the Html.Partial argument that I enter into it.
By the way my controller and action are like this:
public class TestController : Controller
{
IRepository<Customer> customerrepo = RepositoryFactory.GetRepository<Customer>();
//
// GET: /Test/
public ActionResult Index()
{
Customer cust = customerrepo.GetByID("1");
return View(cust);
}
}
Simply this line to the top of your partial view:
Then you can use
@Modelin your partial view, and it will represent the object you passed in your@Html.Partial("_GenericIndex", Model)call.even you can call @Html.Partial(“_GenericIndex”), which will passon the model of the current page to the partial page.