0
사이트에 모듈을 추가하기위한 ASP.NET MVC 양식이 있습니다. 뷰에는 "Name"및 "Content"속성이있는 강력한 형식의 ViewModel이 있습니다. 이 양식에는 모듈에 섹션을 추가하기위한 하위 양식이 있습니다. 하위 양식에는 섹션 개체에 적용 할 때 "이름"및 "콘텐츠"라는 필드가 있습니다. 그러나 나에게 불행히도 빌트인 HTML 도우미 함수는 뷰 모델의 일치하는 속성 값에이 필드를 자동 바인딩하는 것처럼 보입니다. 완전히 다른 개체에 적용하기위한 것이지만.ASP.NET에서 HtmlHelpers의 예기치 않은 부작용
예 클래스 :
public class Module
{
public string Name {get;set;}
public string Content {get;set;}
// ...
}
public class Section
{
public string Name {get;set;}
public string Content {get;set;}
// ...
}
형태 :
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Module>" %>
<!-- rest of page here -->
<%using (var form = Html.BeginForm("AddSection", "Modules")){%>
<ul class="form">
<li>
<label for="Number">Section Number:</label>
<%=Html.TextBox("Number", null, new { size=5, maxlength=5 })%>
<%=Html.ValidationMessage("Number")%>
</li>
<li>
<label for="Name">Section Name:</label>
<%=Html.TextBox("Name")%>
<%=Html.ValidationMessage("Name")%>
</li>
<li>
<div style="width: 75%;">
<label for="Content">Section Content: (<a href="http://textile.thresholdstate.com" target="_blank">formatting help</a>)</label>
<%=Html.TextArea("Content", null, new { @class = "text-entry" })%>
<%=Html.ValidationMessage("Content")%>
</div>
</li>
<li>
<div style="width: 75%;">
<label>Content Preview: (<a href="#" onclick="togglePreviewPane(true); return false;">Show/Hide</a>)</label>
<div id="PreviewBox" class="black-border text-entry"> </div>
</div>
</li>
</ul>
<input type="hidden" id="ModuleID" name="ModuleID" value="<%=Model.ID%>" />
<input type="submit" id="SubmitButton" name="SubmitButton" value="Add Section" />
<%}%>
나는 이름과 내용 입력이 빈 밖으로 시작하지만, HTML 헬퍼없이 페이지의 뷰 모델에 prebinding 것으로 보인다 것으로 기대 내 방향. 나는이를 중지 할 수 있습니다 ... 어떻게
하하 너무 재주 '간단 공백을 텍스트 상자를 강제로
<%=Html.TextBox("Name",string.Empty)%>
을 넣어. 나는 일세. :( – Chris