我提交此表单时,
@model App.Data.ViewModels.ManageUserAccountViewModel
@{
ViewBag.Title = "Manage";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="col-sm-12">
<h2>Manage Account</h2>
<hr />
</div>
@using (Html.BeginForm("Save", @ViewContext.RouteData.Values["controller"].ToString(), FormMethod.Post, new { id = "form" }))
{
@Html.AntiForgeryToken()
<div class="col-sm-12">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
@Html.HiddenFor(m => m.CurrentUser.Id)
@Html.LabelFor(m => m.CurrentUser.FirstName)
@Html.TextBoxFor(m => m.CurrentUser.FirstName, new { @class = "form-control col-sm-12" })
@Html.ValidationMessageFor(m => m.CurrentUser.FirstName)
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
@Html.LabelFor(m => m.CurrentUser.LastName)
@Html.TextBoxFor(m => m.CurrentUser.LastName, new { @class = "form-control col-sm-12" })
@Html.ValidationMessageFor(m => m.CurrentUser.LastName)
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
@Html.LabelFor(m => m.CurrentUser.Email)
@Html.TextBoxFor(m => m.CurrentUser.Email, new { @class = "form-control col-sm-12" })
@Html.ValidationMessageFor(m => m.CurrentUser.Email)
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
@Html.LabelFor(m => m.CurrentUser.UserName)
@Html.TextBoxFor(m => m.CurrentUser.UserName, new { @class = "form-control col-sm-12" })
@Html.ValidationMessageFor(m => m.CurrentUser.UserName)
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
@Html.LabelFor(m => m.CurrentUser.PhoneNumber)
@Html.TextBoxFor(m => m.CurrentUser.PhoneNumber, new { @class = "form-control col-sm-12" })
@Html.ValidationMessageFor(m => m.CurrentUser.PhoneNumber)
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
@Html.HiddenFor(m => m.CurrentUserPassword.Id)
@Html.LabelFor(m => m.CurrentUserPassword.CurrentPassword)
@Html.PasswordFor(m => m.CurrentUserPassword.CurrentPassword, new { @class = "form-control col-sm-12" })
@Html.ValidationMessageFor(m => m.CurrentUserPassword.CurrentPassword)
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
@Html.LabelFor(m => m.CurrentUserPassword.NewPassword)
@Html.PasswordFor(m => m.CurrentUserPassword.NewPassword, new { @class = "form-control col-sm-12" })
@Html.ValidationMessageFor(m => m.CurrentUserPassword.NewPassword)
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
@Html.LabelFor(m => m.CurrentUserPassword.ConfirmNewPassword)
@Html.PasswordFor(m => m.CurrentUserPassword.ConfirmNewPassword, new { @class = "form-control col-sm-12" })
@Html.ValidationMessageFor(m => m.CurrentUserPassword.ConfirmNewPassword)
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<hr />
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<div class="clearfix">
<div class="pull-right">
<input type="submit" value="Save" class="btn btn-primary" />
@Html.ActionLink("Cancel", "Index", @ViewContext.RouteData.Values["controller"].ToString(), new { }, new { @class = "btn btn-outline-secondary" })
</div>
</div>
</div>
</div>
</div>
</div>
}
一堆未知的依赖项出现在我的URL中。我不确定发生了什么。当我离开页面并重新加载页面时,它消失了。
www.website.com/Manage?Resolver=System.Web.Mvc.DependencyResolver%2BCacheDependencyResolver&AsyncManager=System.Web.Mvc.Async.AsyncManager&ActionInvoker=System.Web.Mvc.Async.AsyncControllerActionInvoker&HttpContext=System.Web.HttpContextWrapper&ModelState=System .Web.Mvc.ModelStateDictionary&Profile = System.Web.Profile.DefaultProfile&Request = System.Web.HttpRequestWrapper&Response = System.Web.HttpResponseWrapper&RouteData = System.Web.Routing.RouteData&Server = System.Web.HttpServerUtilityWrapper&Session = System.Web.HttpSessionStateWrapper&TempProvider .Mvc.SessionStateTempDataProvider&Url = System.Web.Mvc.UrlHelper&User = System.Security.Claims.ClaimsPrincipal&ViewEngineCollection = System.Web.Mvc.ViewEngineCollection&ControllerContext = System.Web.Mvc.ControllerContext&TempData = System.Web.Mvc.TempDataDictionary&ValidateRequest = True&Value .Mvc.ValueProviderCollection&ViewBag = System.Web.Mvc.DynamicViewDataDictionary&ViewData = System.Web.Mvc.ViewDataDictionary
这是我的控制人
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Save(ManageUserAccountViewModel Input)
{
if (!ModelState.IsValid)
{
return View("Index", Input);
}
UpdateUserViewModel uuvm = new UpdateUserViewModel
{
Id = Input.CurrentUser.Id,
Email = Input.CurrentUser.Email,
UserName = Input.CurrentUser.UserName,
PhoneNumber = Input.CurrentUser.PhoneNumber,
FirstName = Input.CurrentUser.FirstName,
LastName = Input.CurrentUser.LastName
};
usersData.Update(uuvm);
if (Input.CurrentUserPassword.CurrentPassword != null)
{
usersData.UpdateUserPassword(Input.CurrentUserPassword);
}
TempData["Success"] = "Profile "+AspNetEventLogs.Update;
return RedirectToAction("Index", this);
}
我不确定该怎么做才能删除它,还没有看到它在其他地方发生过。
答案 0 :(得分:3)
问题是由您造成的
return RedirectToAction("Index", this);
其中this
是控制器(及其属性生成路由值)
应该是
return RedirectToAction("Index");
或者如果您要将模型传递给Index()
方法,那么
return RedirectToAction("Index", Input);