在ASP.NET MVC与形式submisison错误为什么我收到一个404资源星火视图引擎没有发现?
-
21-09-2019 - |
题
我的观点:
/用户/ EditUserName / 2 /我
<viewdata model="EditUserNameViewData" />
<form action="~/User/EditUserName" method="post" class="span-15 last">
!{Html.TextBox("newUserName")}
<Submit id='"chooseNewName"' value='"Choose new name"' />
</form>
控制器操作:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult EditUserName(int id)
{
EditUserNameViewData vd = new EditUserNameViewData();
vd.ExistingName = _userRepository.Get(id).UserName;
return View("EditUserName", vd);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditUserName(string newUserName)
{
try
{
// fails
}
catch(RulesException errors)
{
errors.AddModelStateErrors(ModelState, string.Empty);
return View();
}
}
返回查看()似乎不工作,因为它重定向到
/用户/ EditUserName
和给我一个404错误。 WTF?我使用XVAL上为此工程验证和一切只是不能让它与信息的用户把在框中显示重新显示前一页。任何人都知道我在做什么错?这是推动我疯了!
修改强>
我不知道这是Spark或错误究竟发生了什么事。当我加入EditUserName.aspx页,我不再得到一个404错误,它的正常工作,通过reshowing页面没有问题???如何赫克是其他人没有运行到这个问题?我读过的一切,我能找到的,我看不出有什么毛病我在做什么。为什么它与普通视图引擎工作?我所以不希望切换回只使用用户输入的其他人,但我觉得我在这里有没有其他的选择。
查看:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<form action="/User/EditUserName/<%= ((EditUserNameViewData)ViewData.Model).User.Id %>/<%= ((EditUserNameViewData)ViewData.Model).User.UserName %>" method="post" class="span-15 last">
<input type="text" id="newUserName" name="newUserName" />
<input type="submit" id="chooseNewName" value="Choose new Name" />
</form>
解决方案
我在我的母版页中调用Html.RenderAction。我是“后”荷兰国际集团自己的状态,但我的操作方法对它的[AcceptVerbs(HttpVerbs.Get)]属性 - 这是迫使没有找到一个404错误,这是很明显我的错。超级高兴我想通了,但吉兹什么是痛苦。
不隶属于 StackOverflow