I want to fill with a value of the @Html.Editor
when the page is loaded. Here is my failed attempt :
@Html.EditorFor(m => m, new { htmlAttributes = new { @class = "form-control" } })
At the top of the Razor page , I have this :
@model string
And this is my controller :
public ActionResult YeniBelge(string KimlikNo)
{
return View((object)KimlikNo);
}
It says value can't be null.
How can I make this correct? Thanks.
I suspect you are trying to assign a string that could be null to your model, which can never be null. Create a ViewModel class and use it instead:
And then in your view:
Like @vortex pointed out you need to use the EditorFor template.
If you have your model loaded at the top of the page this will fill in the form with the current value of the model field.
In your controller change to the following.
in your view I suspect that you are not finding the model. You need to include your project name when calling the Model.
I would suggest actually saving the View model we created within the Models folder under a View models file and then you would call the following instead.
Fill your model with data in controller, then use