子操作不允许执行重定向操作MVC4
我对MVC还是陌生的.这使我整日发疯,我一直在阅读,似乎我的代码结构中可能存在一些基本错误.但是我正在努力查看它们的确切含义.据我所知,我什至不使用儿童动作?
Im very new to MVC and messing around. This has been driving me crazy all day, i have been reading around and it seems that i may have some fundamental errors in the structure of my code. But i am struggling to see what they are exactly. As far as i can see i am not even using a child action?
在返回的RedirectToAction行上引发了错误.
The error is being thrown on the return RedirectToAction line.
我有一个要以模式形式显示的注册表.这种模式可以在很多页面上看到-因此我创建了一个返回部分视图的操作.
I have a registration form that i am displaying in a modal. This modal will be available to see on many pages - so i created an action that returns a partial view.
[AllowAnonymous]
public ActionResult RegisterPartial()
{
return PartialView(new RegisterModel());
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult RegisterPartial(RegisterModel model)
{
if (ModelState.IsValid)
{
//do stuff
return RedirectToAction("Data", "Settings", new { id = model.UserName });
}
// If we got this far, something failed, show form again
return PartialView(model);
}
此刻正在我的主页上调用-但最终将在许多页面上调用.
This is called from my home page at the moment - but will be called from many pages eventually.
<div class="modal fade" id="signUpModal">
@Html.Action("RegisterPartial", "Account")
</div>
<a href="#" style="color:#fff;" class=" btn btn-lg btn-primary" data-toggle="modal" data-target="#signUpModal">SignUp</a>
这是局部视图本身
@model Prog.Models.RegisterModel
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Signup</h4>
</div>
@using (Html.BeginForm())
{
<fieldset>
<div class="modal-body">
<p class="message-info">
</p>
@Html.ValidationSummary()
@Html.AntiForgeryToken()
<ol>
<li>
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName, new { @maxlength = "13" })
@Html.ValidationMessageFor(m => m.UserName)
</li>
<li>
@Html.LabelFor(m => m.email)
@Html.TextBoxFor(m => m.email)
@Html.ValidationMessageFor(m => m.email)
</li>
<li>
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password)
</li>
<li>
@Html.LabelFor(m => m.ConfirmPassword)
@Html.PasswordFor(m => m.ConfirmPassword)
</li>
@Html.ValidationMessageFor(m => m.ConfirmPassword)
</ol>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Post</button>
</div>
</fieldset>
}
</div></div>
任何帮助将不胜感激!在此先感谢:)
Any help would be most appreciated! Thanks in advance :)
原来是因为我没有正确填写html begin form语句.
Turns out it was because i didnt fill out the html begin form statement correctly.
@using (Html.BeginForm("RegisterPartial", "Account", FormMethod.Post , new { @class = "form-horizontal" }))
现在可以使用.