I'm trying to pass data between views and I keep getting a null value when I try to pass it through.
All I want is for the actionlink from "contractordetails" view to pass its contractorid on the page to the next view "contractorrequest" so it can be displayed.
The UserId and User Name is working I just keep getting an error as shown below indicating its a null entry.
Where am I going wrong?
My code:
@Html.ActionLink(
linkText: "Contractor Area",
actionName: "ContractorRequest",
controllerName: "ConDashboard",
routeValues: new {area = "Contractor",id = Model.ContractorId},
htmlAttributes: null )
Controller
[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);
}
View
@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>
