Reputation: 31333
Consider the following partial view Common.cshtml ...
<input id="CommonControl" />
I want to render it with ...
@Html.Partial("Common", "PersonNamespace")
@Html.Partial("Common", "CarNamespace")
and the final output to be...
<input id="PersonNamespaceCommonControl" />
<input id="CarNamespaceCommonControl" />
How would I define the above partial with a model to accomplish this?
For example...
<input id="@modelCommonControl" />
wouldn't work. What would be the correct Razor syntax?
Upvotes: 1
Views: 1870
Reputation: 18974
Note that @Html.PartialView()
accepts only 2 types, say, model
and ViewDataDictionary
as second arg, Not a string
! So you need to implement partial views as desired. You can Define a ViewModel for Partial View like this example:
ViewModel:
public class Partial{
public string name {get; set;}
//other fields
}
Partial:
@model project.ViewModels.Partial
<input id="@string.Concat(Model.name,"CommonControl")" />
With considering to avoid model conflict in one page.
Upvotes: 4