Basically, instead of writing plain old Html to build a form, I would like to invoke a helper method and have that return what I need.
<div class="contacto-container">
<h1>Envíenos sus consultas:</h1>
@Html.Editor("BuzonDeSugerenciaModel", "BuzonDeSugerenciaModel")
<div class="separator"></div>
</div>
This isn’t really doing what I think it would do.
It outputs:
<input id="BuzonDeSugerenciaModel"
class="text-box single-line"
type="text" value="" name="BuzonDeSugerenciaModel">
And not the collection of inputs I declared in the Model class, BuzonDeSugerenciaModel.
If this were a strongly type View, it would be fine if I went:
@Html.EditorForModel()
However, since this is run in the _Layout.cshtml file, I need something else. I can’t quite figure out a way to do this.
Any ideas?
You need to create a partial view that is strongly typed to your
BuzonDeSugerenciaModelclass. This partial view will live in yourViews > Shareddirectory.Something like this (
_BuzonDeSugerenciaModel.cshtml):Then, in your _Layout.cshtml, you can call:
You will need to pass an instance of
BuzonDeSugerenciaModelas the second argument toPartial(). If you do not have one passed form theController, something like this will work: