2010-02-11 6 views
1

사용자 프로필 데이터를 표시하고 편집하기위한 매우 간단한 컨트롤러와보기가 있습니다.ASP.NET MVC 양식이 게시되지 않습니다.

문제는 양식이 게시되지 않는다는 것입니다. 다음과 같이

<%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %> 

<% using (Html.BeginForm()) {%> 
<div> 
    <fieldset> 
     <p> 
      <label for="Title"> 
       Title:</label> 
      <%= Html.TextBox("Title", Model.Title) %> 
      <%= Html.ValidationMessage("Title", "*") %> 
     </p> 
     <p> 
      <label for="FirstName"> 
       FirstName:</label> 
      <%= Html.TextBox("FirstName", Model.FirstName)%> 
      <%= Html.ValidationMessage("FirstName", "*") %> 
     </p> 
     <p> 
      <label for="LastName"> 
       LastName:</label> 
      <%= Html.TextBox("LastName", Model.LastName)%> 
      <%= Html.ValidationMessage("LastName", "*") %> 
     </p> 
    </fieldset> 
    <fieldset> 
     <legend>Contact with the Encephalitis Society</legend> 
     <p> 
      <label for="Contactable"> 
       Allow The Encephalitis Society to contact me (we will not contact you unless this 
       is checked):</label> 
      <%= Html.CheckBox("Contactable", Model.Contactable)%> 
      <%= Html.ValidationMessage("Contactable", "*") %> 
     </p> 
     <p> 
      <label for="SubscribeNewsletter"> 
       I would like to receive e-newsletters:</label> 
      <%= Html.CheckBox("SubscribeNewsletter", Model.SubscribeNewsletter)%> 
      <%= Html.ValidationMessage("SubscribeNewsletter", "*") %> 
     </p> 
     <p> 
      <label for="wantMembershipInfoPackage"> 
       I would like more information about becoming a member of the Encephalitis Society:</label> 
      <%= Html.CheckBox("wantMembershipInfoPackage", Model.IsMember)%> 
      <%= Html.ValidationMessage("wantMembershipInfoPackage", "*")%> 
     </p> 
     <p> 
      <label for="IsMember"> 
       I am already a member of the Encephalitis Society:</label> 
      <%= Html.CheckBox("IsMember", Model.IsMember)%> 
      <%= Html.ValidationMessage("IsMember", "*") %> 
     </p> 
     <p> 
      <label for="wantToBeRegularDonor"> 
       I would like to make a regular donation to the Encephalitis Society:</label> 
      <%= Html.CheckBox("wantToBeRegularDonor", Model.IsMember)%> 
      <%= Html.ValidationMessage("wantToBeRegularDonor", "*")%> 
     </p> 
    </fieldset> 
    <hr /> 
    <%=Html.ActionLink("Cancel (Return to My Page)", "MyPage", "Members", null, new { @class = "LinkButton LeftButton" })%> 
    <input class="LinkButton RightButton" type="submit" value="Save" /> 
</div> 
<% } %> 

컨트롤러는 다음과 같습니다 : 다음과 같이 나는 ...

코드 문제를 볼 수 없습니다

public class ProfileController : Controller 
{ 

    WebProfile p = WebProfile.Current; 
    Member member = new Member(); 

    // GET: Shows details of the Profile 
    public ViewResult Show() 
    { 
     ViewData["CategoryRole"] = member.CategoryRoleUserFriendly; 
     return View(p); 
    } 

    // GET: /Profile/New - displays a template to create the Profile 
    public ViewResult New() 
    { 
     ViewData["SaveButtonText"] = "Next >>"; 
     return View(p); 
    } 

    // POST: /Profile/New 
    [AcceptVerbs(HttpVerbs.Post)] 
    public ActionResult New(FormCollection formValues) 
    { 
     try 
     { 
      WebProfile.GetProfile(member.UserName); 
      UpdateModel(p); 
      return RedirectToAction("MyPage", "Members"); 
     } 
     catch 
     { 
      ViewData["SaveButtonText"] = "Next >>"; 
      return View(); 
     } 
    } 

    // GET: /Profile/Edit - displays a template to create the Profile 
    public ViewResult Edit() 
    { 
     ViewData["SaveButtonText"] = "Save >>"; 
     return View(p); 
    } 

    // POST: /Profile/Edit - displays a template to create the Profile 
    [AcceptVerbs(HttpVerbs.Post)] 
    public ActionResult Edit(FormCollection formValues) 
    { 
     try 
     { 
      WebProfile.GetProfile(member.UserName); 
      UpdateModel(p); 
      return RedirectToAction("Show"); 
     } 
     catch 
     { 
      return View(); 
     } 
    } 
} 

}

아무것도 당신을 밖으로 도약 하는가?

+0

Html.BeginForm()에 작업 이름을 입력하면 어떻게됩니까? – Gregoire

답변

4

나는 그것을 해결하고 내가 것 여기 세부 그것은 그런 작은 문제 :

문제는 누락 된 따옴표 (")를, 다음되면서 :

<p class="Note>PLEASE NOTE: All items below are Optional</p> 
<%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %> 

<% using (Html.BeginForm()) {%> 
<div> 
    <fieldset> 
     ... 

당신은 발견 할 수 ?

<p class="Note>... 

가되어 있어야합니다 :

<p class="Note"> 
그것은 나에게 일을했다, 걱정하지 마세요

(Html.BeginForm()) %>을 (를) 사용하여 < % 전에 누락 된 견적이 양식 POST 동작을 스큐 할만큼 충분했습니다. 오류가없고 코드 채색이 변경되지 않았습니다. 시각적 인 표시가 없습니다. 아무것도.

하나는 기억! :

양식 게시하지 않습니다 때, Html.BeginForm() 라인 위의 잘못된 HTML을 찾습니다.

관련 문제