asp.net-mvc2 - Ajudantes fortemente digitados que não usam o Model?
Ao usar auxiliares de tipo forte no MVC2, os valores do campo de entrada não são obtidos da propriedade Model quando uma postagem é feita. Esse comportamento padrão é
ista (fortemente tipada) com ajudantes fortemente tipados:
<div class="editor-label">
<%: Html.LabelFor(model => model.Name) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Name) %>
<%: Html.ValidationMessageFor(model => model.Name) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Price) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Price) %>
<%: Html.ValidationMessageFor(model => model.Price) %>
</div>
ção do @ Controller para: / Produto / Editar / 5
public ActionResult Edit(int id)
{
var p = new Product();
p.Name = "product 1";
p.Price = "100";
return View(p);
}
Saída HTML:
<div class="editor-label">
<label for="Name">Name</label>
</div>
<div class="editor-field">
<input id="Name" name="Name" type="text" value="product 1" />
</div>
<div class="editor-label">
<label for="Price">Price</label>
</div>
<div class="editor-field">
<input id="Price" name="Price" type="text" value="100" />
</div>
ção do @ Controller para: / Produto / Editar / 5
[HttpPost]
public ActionResult Edit(Product p)
{
p.Name = "prrrrrrd 2";
return View(p);
}
Html output após a postagem do formulário (abaixo, eu esperaria que o valor da entrada com id = "Name" fosse "prrrrrrd 2. De onde o auxiliar fortemente digitado obtém seu valor?):<div class="editor-label">
<label for="Name">Name</label>
</div>
<div class="editor-field">
<input id="Name" name="Name" type="text" value="product 1" />
</div>
<div class="editor-label">
<label for="Price">Price</label>
</div>
<div class="editor-field">
<input id="Price" name="Price" type="text" value="100" />
</div>