1
MVC2에서 강력한 형식의 도우미를 사용하는 경우 게시물을 만들 때 입력 필드 값이 Model 속성에서 가져 오지 않습니다. 이 기본 동작입니까?asp.net-mvc2 - 모델을 사용하지 않는 강력한 유형의 도우미?
강력한 형식의 도우미와 (강력한 형식)보기 :
<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>
컨트롤러의 행동은 :/제품/편집/5
public ActionResult Edit(int id)
{
var p = new Product();
p.Name = "product 1";
p.Price = "100";
return View(p);
}
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>
,
컨트롤러 조치 :/제품/편집/5
[HttpPost]
public ActionResult Edit(Product p)
{
p.Name = "prrrrrrd 2";
return View(p);
}
내가 prrrrrrd 2. 어디 않습니다 "로 ID ="이름 "과 입력 값을 기대 아래 양식 포스트 (후
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>
이전 프로젝트에서는이 점을 기억하지 못합니다. ModelState가 비활성화되었거나 이전 '릴리스'의 어떤 것이 가능합니까? – ReFocus
@ReFocus, 이전 프로젝트가 의미하는 것이 확실하지 않습니다 *. ASP.NET MVC 1.0을 의미하는 경우 강력하게 형식화 된 도우미 ('For'로 끝나고 첫 번째 인수로 람다 식을 사용)가 없습니다. –
방금 두 번 확인했습니다. '기본'도우미는 모델 값보다 먼저 ModelState를 사용합니다. 이 동작은 MVC2에서 새로 추가 되었습니까? – ReFocus