Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value cannot be null or empty.\r\nParameter name: name

when i go to cshtml page this error occur:

An exception of type 'System.ArgumentException' occurred in System.Web.Mvc.dll but was not handled in user code

in my cshtml code :

<div class="form-group">
     @Html.Label("Model", new { @class = "control-label col-md-4" })
  <div class="col-md-8">
     @Html.Editor("Model")
  </div>
</div>

enter image description here

but on the other hand if i change my code in @Html.Editor("PropertyModel")

it is working perfectly no error occur .

UPDATE:

in my model:

public class PropertyAssign {
        public int PropertyAssignId { get; set; }

        public string PropertyName { get; set; }

        public string Model { get; set; }


        public DateTime AssignDate { get; set; }
    }

In My Controller:

 public ActionResult Create()
    {
      return View();
    }
like image 247
Nazmul Hasan Avatar asked May 02 '26 12:05

Nazmul Hasan


1 Answers

I've tryed this case and it's very strange, but there is some problem with the identifier of your Model property with usage of @Html.Editor() helper.

@Html.Editor("Model") // throws an exception
@Html.EditorFor(m => m.Model) // works fine

Maybe in this context the meaning of Model is the whole model, which is passed to the view, not the single property. But when I've changed the identifier of the Model property to some other, for example SomeModel, everything is fine.

@Html.Editor("SomeModel") // works fine
@Html.EditorFor(m => m.SomeModel) // works fine

So, the possible solutions are:

  • to change the Editor helper you use or
  • to change your property identifier
like image 90
Tanya Petkova Avatar answered May 05 '26 01:05

Tanya Petkova