I have seen the other Question. But I prefer to answer here maybe it will solve the second problem. Because there are many solutions. But I think maybe the first I gave doesn't allow you to populate this value for some reason.
Could you try this:using a overload of Html.Partial()
method and passing a ViewDataDictionary
with the value you want.
You need to change this line:
@Html.Partial("roomForm", new TerminalHost.Models.roomInfo())
To:
@Html.Partial("roomForm", new TerminalHost.Models.roomInfo(), new ViewDataDictionary { {"buildingId", Model.buildingId} } )
And in your partial view, you can retrieve it like this:
@model TerminalHost.Models.roomInfo
@{
ViewBag.Title = "Create";
}
@{
int buildingId = Convert.ToInt32(ViewData["buildingId"]);
}
........
<div class="editor-field">
@Html.TextBoxFor(model => model.buildingId,new {@Value=buildingId })
@Html.ValidationMessageFor(model => model.buildingId)
</div>
I hope by doing in this way it will solve the second problem.