【发布时间】:2015-07-01 07:27:45
【问题描述】:
我有一个获取用户名和密码并需要将其传递给数据库的视图。我可以传递用户名但不能传递密码。
查看:
<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "label-control" })
@Html.PasswordFor(m => m.UserName, new { @class = "form-control", autofocus = "", value = "Text" })
@Html.ValidationMessageFor(m => m.UserName, null, new { @class = "alert-danger" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new { @class = "label-control" })
@Html.TextBoxFor(m => m.Password, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Password, null, new { @class = "alert-danger" })
</div>
控制器:
public ActionResult EditUserSubmit(string UserName, string Password, string ProcessType)
{
string process;
string name = Url.RequestContext.RouteData.Values["id"].ToString();
process = (ProcessType == "Processed") ? "P" : "B";
DB.Entities.user users = db.users.Where(m => m.username == name).FirstOrDefault();
users.password = Password;
users.processtype = process;
db.SaveChanges();
return RedirectToAction("Manager");
}
更新
这是整个视图
@model NV.Tax.SST.Gateway.MVC.Models.AdministrationModel
@{string name = Url.RequestContext.RouteData.Values["id"].ToString();}
<div class="x-form-wrapper">
<div class="x-form-title">
<h3><strong>User Detail for <b>@Url.RequestContext.RouteData.Values["id"]</b></strong></h3>
</div>
<div class="x-form-body">
<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "label-control" })
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control", autofocus = "", value = "Text" })
@Html.ValidationMessageFor(m => m.UserName, null, new { @class = "alert-danger" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new { @class = "label-control" })
@Html.PasswordFor(m => m.Password, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Password, null, new { @class = "alert-danger" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.ProcessType, new { @class = "label-control" })
@Html.DropDownListFor(m => m.ProcessType, new[]{
new SelectListItem { Text = "Processed", Value = "Processed" },
new SelectListItem { Text = "Both", Value = "Both" }
}, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.ProcessType, null, new { @class = "alert-danger" })
</div>
<div class="form-group">
<a href="/Administration/EditUserSubmit/@name" class="btn btn-lg btn-primary">Save</a>
@Html.ActionLink("Cancel", "Manager", "Administration", null, new { @class = "btn btn-lg btn-default" })
</div>
</div>
</div>
@{
string password = "";
var entity = new NV.Tax.SST.Gateway.DB.Entities.sstpEntities();
var data = from db in entity.users
where db.username == name
select db;
foreach(var item in data)
{
password = item.password;
<script>document.getElementById("Password").defaultValue = "@password"</script>
if (item.processtype == "B")
{
<script>document.getElementById("ProcessType").value = "Both"</script>
}
else
{
<script>document.getElementById("ProcessType").value = "Processed"</script>
}
}
}
【问题讨论】:
-
你能展示你提交表单时使用的JS代码吗?
-
没有JS代码。
-
那么你如何将值传递给操作?通过表单提交 url?
标签: c# html asp.net asp.net-mvc entity-framework