Html ASP.NET MVC表单赢得';t柱
我有一个非常简单的控制器和视图,用于显示和编辑用户配置文件数据 问题是表单无法发布。我看不出有什么问题 代码如下:Html ASP.NET MVC表单赢得';t柱,html,asp.net-mvc,forms,post,Html,Asp.net Mvc,Forms,Post,我有一个非常简单的控制器和视图,用于显示和编辑用户配置文件数据 问题是表单无法发布。我看不出有什么问题 代码如下: <%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %> <% using (Html.BeginForm()) {%> <div> <fieldset> <p>
<%= 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();
}
}
}
<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>
...
}
有什么东西向你扑来吗 我已经解决了这个问题,这是一个非常小的问题,我将在这里详细介绍: 问题是缺少引号(“),如下所示:
<%= 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();
}
}
}
<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">
之前缺少的引号足以破坏表单POST操作。没有错误,没有代码颜色的更改,没有视觉指示。什么都没有
一个要记住的!:
当您的表单无法发布时,请在html.BeginForm()行上方查找格式错误的html。我已经解决了它,这是一个非常小的问题,我将在此处详细介绍: 问题是缺少引号(“),如下所示:
<%= 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();
}
}
}
<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">
之前缺少的引号足以破坏表单POST操作。没有错误,没有代码颜色的更改,没有视觉指示。什么都没有
一个要记住的!:
当表单无法发布时,请在html.BeginForm()行上方查找格式错误的html。如果将操作名称放入html.BeginForm(),会发生什么情况?如果将操作名称放入html.BeginForm(),会发生什么情况?