Dav*_*Dev 14 asp.net-mvc razor asp.net-mvc-3
让我的工作变得非常失败!
在一个视图中......
@model Project.Models.Account.ForgotPasswordModel
@{
ViewBag.Title = "Forgot Password";
}
<h2>ForgotPassword</h2>
<span id='@ViewBag.ReplaceID'>
@Html.Partial("_ForgotPasswordUserNameAjax", ViewData.Model)
</span>
Run Code Online (Sandbox Code Playgroud)
我渲染这个partialView ...
@model Project.Models.Account.ForgotPasswordModel
@{
this.Layout = null;
}
@using (Ajax.BeginForm("ForgotPassword", new AjaxOptions() { UpdateTargetId = ViewBag.ReplaceID, InsertionMode = InsertionMode.InsertAfter }))
{
@Html.ValidationSummary(true, "Forgot Password was unsuccessful. Please correct the errors and try again.")
<div id="login" class="box">
<fieldset>
<h2>Account Information</h2>
<div class="inside">
<div class="editor-label">
@Html.LabelFor(m => m.Username)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Username)
<br />
@Html.ValidationMessageFor(m => m.Username)
<br />
</div>
<p>
<input type="submit" value='Submit' />
</p>
</div>
</fieldset>
</div>
}
Run Code Online (Sandbox Code Playgroud)
而这个控制器动作......
[HttpPost]
public PartialViewResult ForgotPassword(ForgotPasswordModel model)
{
if (String.IsNullOrEmpty(model.Username))
{
ModelState.AddModelError("Username", ForgotPasswordStrings.USER_NAME_REQUIRED);
}
else
{
bool isGood = false;
model.Question = this._security.ValidateUserNameGetSecurityQuestion(model.Username, out isGood);
if (!isGood)
{
ModelState.AddModelError("Username", ForgotPasswordStrings.USER_NAME_INVALID);
}
}
PartialViewResult retVal = null;
if (ModelState.IsValid)
{
retVal = PartialView("ForgotPasswordAnswerAjax", model);
}
else
{
retVal = PartialView("_ForgotPasswordUserNameAjax", model);
}
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
然而,每次,视图只返回PartialView,不包含在布局中.(所以我的PartialView就在屏幕上.没有别的.)我尝试了一些我在网上找到的东西...... http: //www.compiledthoughts.com/2011/01/aspnet-mvc-razor-partial-views-with.html http://stackoverflow.com/questions/4655365/mvc3-submit-ajax-form
但没有解决这个问题.我已将InsertionMode更改为所有值而没有任何更改.我已将@ Html.Partial更改为代码块,如@ {Html.RenderPartial("_ ForgotPasswordUserNameAjax",ViewData.Model); }.
这不起作用......
我的想法(和耐心)已经不多了!
请帮忙!
编辑 PEBKAC.
我忘记了升级项目时,我添加了新的jquery.unobtrusive-ajax.js文件,但从未将它们包含在_Layout.cshtml页面上.添加该库以解决问题.对不起大家!
原帖 我开始认为这是一个bug.再次采用未转换的项目(MVC2)并将其转换为MVC3.我将所有原始页面保留为aspx/ascx格式并运行该项目.我试过了这个页面.同样的问题仍然存在.回到MVC2,它工作正常.再试一次MVC3,问题再次发生.
我使用与此非常类似的页面转换了项目...
http://mattsieker.com/index.php/2010/11/21/converting-asp-net-mvc2-project-to-mvc3/
| 归档时间: |
|
| 查看次数: |
30355 次 |
| 最近记录: |