asp.net mvc 5 - I'm tryng to send two parameters from view to controller but the second is always null -


i'm trying send 2 parameters (httppostedfilebase , model) view create method in controller variable httppostedfile photos gets null values. here controller code:

 public async task <actionresult> create([bind(include =  "id,name,description")] models.environment environment, httppostedfilebase photos)         {             if (modelstate.isvalid)             {                 if (photos!=null)                 {                     datablobimage datablobimage = new datablobimage();                     environment.logo = await                      datablobimage.createimage("environment",                      environment.id.tostring(), photos);                 }                     //creation date                     environment.creationdate = datetime.now;                     //get creation user id                     environment.creationuser = 1;                     //by default when create user active                     environment.active = true;                     db.environment.add(environment);                     await db.savechangesasync();                     return json(new { success = true });                 }                  return view(environment);             } 

view code:

@using (html.beginform("modalcreate", "environment",          formmethod.post,         new { enctype = "multipart/form-data"     })) {           @html.antiforgerytoken()         <div class="modal-header create-window">         <button type="button" class="close"          data-dismiss="modal" aria-   hidden="true">&times;</button>         <h4 class="modal-title" id="mymodallabel">crear nuevo ambiente</h4>         </div>         <div class="modal-body">          <div class="form-horizontal">             @html.validationsummary(true, "", new { @class = "text-danger" })             <div class="form-group">                 @html.labelfor(model => model.name,                  htmlattributes: new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.editorfor(model => model.name,                      new { htmlattributes = new { @class = "form-control" } })                     @html.validationmessagefor(model => model.name, "",                      new { @class = "text-danger" })                 </div>             </div>              <div class="form-group">                 @html.labelfor(model => model.description,                  htmlattributes: new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.editorfor(model => model.description,                     new { htmlattributes = new { @class = "form-control" } })                     @html.validationmessagefor(model => model.description, "",                     new { @class = "text-danger" })                 </div>             </div>              <div class="form-group">                 <div class="col-md-10">                     <label for="file">subir imagen:</label>                     <input id="photos" name="photos" type="file"                       style="width: 100%;" />                 </div>              </div>               <div class="modal-footer">                 <button class="btn" data-dismiss="modal">cancelar</button>                 <input class="btn btn-primary" type="submit" value="crear" />              </div>              </div>          </div>       } 

i think don't need pass additional parameter that. can alway access below inside action method:

 httppostedfilebase file =  request.files["nameofyourfileuploadcontrol"]; 

hope help.


Comments