我有一個包含表單的局部視圖,並且此局部視圖存在於包含其他一些表單和html的視圖中。
當我按提交併且驗證失敗時,它會在URL中顯示此部分視圖表單操作,而不是原始URL。部分視圖在URL中顯示其操作而不是容器視圖操作
父視圖「用戶帳戶」: - 登錄局部視圖 - 註冊局部視圖
原始地址時,頁面打開爲:/用戶/帳戶
URL時,寄存器驗證失敗變成:/用戶/寄存器
這裏是我的局部視圖:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PicGhost.Website.ViewModels.RegisterViewModel>" %>
<% using (Html.BeginForm("Register", "Users", FormMethod.Post)) {%>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.UserName) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.UserName) %>
<%: Html.ValidationMessageFor(model => model.UserName) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Email) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Email) %>
<%: Html.ValidationMessageFor(model => model.Email) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Password) %>
</div>
<div class="editor-field">
<%: Html.PasswordFor(model => model.Password)%>
<%: Html.ValidationMessageFor(model => model.Password) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.ConfirmPassword) %>
</div>
<div class="editor-field">
<%: Html.PasswordFor(model => model.ConfirmPassword) %>
<%: Html.ValidationMessageFor(model => model.ConfirmPassword) %>
</div>
<p>
<input type="submit" value="Register" />
</p>
</fieldset>
<% } %>
和註冊行動:
[HttpPost]
public ActionResult Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
IUser user = _factory.CreateUser(model.UserName, model.Email, model.Password);
UserRepository.Add(user);
return RedirectToAction("Index");
}
return View(model);
}
如何避免顯示這個錯誤的URl並保留原始URL?
原始地址:
驗證網址後:
我的確如你在你的例子中寫的那樣,但它給了我和我的問題相同的結果:(你知道問題出在哪裏嗎? – 2010-11-25 15:04:49