Reputation: 1546
this my view, I catch an error in
@Html.EditorFor(model => model.FacebookId)
model is null
But in the var @Model
, I have my viewModel with all values
This my view:
@model Registration.Front.Web.Models.RegistrationViewModel
@using Registration.Domain.Entities.Enum;
@using Registration.Front.Web.Helpers;
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Registration</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
@{string visibleFb = (!Model.FBParam) ? "display:none" : "display:inline";
<div id="fb" style="@visibleFb">
<div class="editor-label">
FacebookId
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FacebookId)
</div>
</div>
Upvotes: 0
Views: 133
Reputation: 685
Did you note that you did not get that error for Model.FBParam and for Model.Facebookid? This Means your FacebookId property is nullable and is sent null from action. Also use specific kind of control by your data type like dropdown for int with reference or textbox for string jetc.
Upvotes: 0
Reputation: 7605
I think you need to write it as
@Html.EditorFor(model => Model.FaceBookId) //<--Note the uppercase "M"
So model is just a lamda variable, while Model points to whatever is declared as @model
You can see that in the Watch window it's Model, not model, that you're interested in here.
Upvotes: 2
Reputation: 182
Check in your Action method. Are you returning populated model from you Action ?
Upvotes: 0