c# - Viewmodel always null following file upload -
i creating page in asp.net mvc user can upload file, along details file textboxes.
for use viewmodel, , simple method configuration. page populated correctly [get] method, , user can choose file , enter details, once 'submit' button clicked, , [post] method called, viewmodel null.
i have done research on , have tried:
- adding enctype="multipart/form-data"
- simply using file separate parameter
to no avail.
here controller methods:
public actionresult filecomment(int id) { //set [get] view return view("filecomment", obj); } //this method's viewmodel null [httppost] public actionresult filecomment(calibrationcommentviewmodel file) { //save file database return view("edit", new { id = file.id }); } here part of view:
@using (html.beginform("filecomment", "calibration", formmethod.post, new { enctype = "multipart/form-data", @data_ajax = "false" })) { @html.hiddenfor(m => m.id) <div class="container"> <h4>add file @model.id</h4> <hr /> <div class="row"> <div class="col-md-1">g @html.labelfor(model => model.file, htmlattributes: new { @class = "control-label" }) </div> <div class="col-md-2"> @html.textboxfor(model => model.file, new { type = "file" }) </div> <div class="col-md-9"></div> </div> <br /> <div class="row"> <div class="col-md-1"> @html.labelfor(model => model.attachmenttype, htmlattributes: new { @class = "control-label" }) </div> <div class="col-md-2"> @html.dropdownlistfor(model => model.attachmenttype, model.attachtypelist, new { @class = "form-control" }) </div> <div class="col-md-9"></div> </div> <br /> <div class="row"> <div class="col-md-1"> @html.labelfor(model => model.date, htmlattributes: new { @class = "control-label" }) </div> <div class="col-md-2"> @html.editorfor(model => model.date) </div> <div class="col-md-9"></div> </div> <br /> <div class="row"> <div class="col-md-1"> @html.labelfor(model => model.description, htmlattributes: new { @class = "control-label" }) </div> <div class="col-md-2"> @html.textareafor(model => model.description, new { cols=35, @rows=3}) </div> <div class="col-md-9"></div> </div> <br /> <div class="row"> <div class="col-md-1"></div> <div class="col-md-2"> <button type="submit" onclick="javascriptfunction()">add @model.id</button> </div> <div class="col-md-9"></div> </div> </div> }
change
public actionresult filecomment(calibrationcommentviewmodel file) to
public actionresult filecomment(calibrationcommentviewmodel model)
Comments
Post a Comment