Я пытаюсь передать данные между представлениями и получаю нулевое значение, когда пытаюсь передать их.
Все, что я хочу, это чтобы actionlink из представления "contractordetails" передавал свой подрядчик на странице следующему представлению "contractorrequest", чтобы его можно было отобразить.
Идентификатор пользователя и имя пользователяЯ просто продолжаю получать сообщение об ошибке, как показано ниже, указывающее на пустую запись.
![enter image description here](https://i.stack.imgur.com/HimIg.png)
Куда я иду не так?
Мойкод:
@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>