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


when go cshtml page error occur:

an exception of type 'system.argumentexception' occurred in system.web.mvc.dll not handled in user code

in 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 other hand if change code in @html.editor("propertymodel")

it working no error occur .

update:

in 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 controller:

 public actionresult create()     {       return view();     } 

the reason exception thrown htmlhelpers inspect viewdata values bind to. viewdata typeof viewdatadictionary contains property model (which model pass view).

in case, not return model view viewdata.model null , exception thrown.

to solve this, use typed editorfor(m => m.model) (or textboxfor(m => m.model) should doing in case. if not pass model view, still generate correct html without throwing exception.

<input type="text" name="model" id="model" value="" /> 

but best practice pass model anyway, controller method should be

public actionresult create() {   return view(new propertyassign()); } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -