【发布时间】:2019-03-01 23:42:14
【问题描述】:
我正在尝试在视图之间传递数据,但当我尝试传递数据时,我一直得到一个空值。
我想要的只是“contractordetails”视图中的actionlink将其在页面上的contractorid传递到下一个视图“contractorrequest”以便显示。
UserId 和 User Name 正常工作我只是不断收到如下所示的错误,表明其为空条目。
我哪里错了?
我的代码:
@Html.ActionLink(
linkText: "Contractor Area",
actionName: "ContractorRequest",
controllerName: "ConDashboard",
routeValues: new {area = "Contractor",id = Model.ContractorId},
htmlAttributes: null )
控制器
[HttpGet]
public ActionResult ContractorRequest(ContractorVM model, int contractorid)
{
int id = model.ContractorId;
var addrequest = new AddCalendarRequestVM();
addrequest.User = new UserVM();
string username = User.Identity.Name;
using (Db db = new Db())
{
UserDTO dto = db.Users.FirstOrDefault(x => x.Username == username);
addrequest.User = new UserVM(dto);
}
return View("ContractorRequest", addrequest);
}
查看
@using (Html.BeginForm("ContractorRequest", "ConDashboard", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<form class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.User.UserId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.User.UserId, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.User.UserId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.User.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.User.Name, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.User.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Contractor.ContractorId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Contractor.ContractorId, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.Contractor.ContractorId, "", new { @class = "text-danger" })
</div>
</div>
【问题讨论】:
标签: html asp.net asp.net-mvc