Model: ProjectModel declared project id in model.
public class ProjectModel
{
public List<string> BusinessPriority { get; set; }
public string projectId { get; set; }
public string sSessionValue
{
get;
set;
}
}
Index.html: index html code I will get autopopulate value in the below text box.but model property is null.
<div class="col-md-2">
<div class="col-md-11">
<label class="control-label">Project Id</label>
</div>
</div>
<div class="col-md-2">
<div class="form-group form-group-md">
@Html.TextBoxFor(model => model.projectmodel.projectId, new { @class = "form-control", id = "ProjectId",@readonly = "true" })
</div>
</div>
Controller: Home Controller code below Session variables [HttpPost]
public ActionResult Index(CommonModel data)
{
// Assign value into session
Session["ProjectId"] = data.projectmodel.projectId;
// Redirect view
return RedirectToAction("Financials");
}
public ActionResult Financials()
{
// Create object of model call for call properties and set value
var vSessionValue = new CommonModel();
// Session["ProjectId"] = Request["ProjectId"].ToString();
try
{
// check existing value into session
if ((Object)Session["ProjectId"] != null)
// assign value into properties
vSessionValue.projectmodel.sSessionValue = Session["ProjectId"].ToString();
else
// if session expired than set custom message
vSessionValue.projectmodel.sSessionValue = "Session Expired";
}
catch
{
}
// return value to view
return View(vSessionValue);
}