In MVC4, with the Razor view engine, we have a group of items that we wish to group in a partial view, so that we can reuse the code. Currently our main views we have something along the lines of:
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.Description, new { @id = "Common" })
<div class="FormValidationText">
@Html.ValidationMessageFor(model => model.Description)
</div>
</div>
We want to be able to use this logic but with a wide variety of models, not all of which will want to use the model.Description.
For example, we would like to use model Foo, and create the above for the Foo.Bar
property, but we also want to be able to use the Hello model's Hello.World
property. These are all of type string, as you would expect since we want to handle the text input from the textarea.
What edits do we need to make in the partial view to say "Use some specified property of any given model, and understand it to be a property of that model, to generate these items". How, subsequently, do we work with the @{Html.RenderPartial(...)}
method to ensure that we have passed the models property?
Please forgive me if this seems a little confused, I am still learning MVC and Razor views.