asp.net mvc - Multiple Attributes Html.BeginForm MVC id and enctype as part of file upload -
as part of file upload (asp.net mvc3) adding id , enctype attributes html.beginform return httppostedfilebase null
model:
public class profilemodel { [uihint("upload")] public httppostedfilebase imageupload { get; set; } }`
profileform.cshtml
@using (html.beginform("update", "profile", new { profileid = viewbag.profileid }, formmethod.post, new { @enctype = "multipart/form-data", @id = "profileform" })) { <div> @html.labelfor(model => model.imageupload) @html.textboxfor(model => model.imageupload, new { type = "file" }) </div> <div class='buttons'> <input type="submit" value='save' /> </div> }
controller
public upload(profilemodel viewmodel) { if (viewmodel.imageupload != null && viewmodel.imageupload.contentlength > 0) { var uploaddir = "~/uploads"; var imagepath = path.combine(server.mappath(uploaddir), viewmodel.imageupload.filename); var imageurl = path.combine(uploaddir, viewmodel.imageupload.filename); viewmodel.imageupload.saveas(imagepath); } }
if remove @id = "profileform"
attribute below getting httppostedfilebase (imageupload) value.
@using (html.beginform("update", "profile", new { profileid = viewbag.profileid }, formmethod.post, new { @enctype = "multipart/form-data"})) { }
i need pass both id , enctype - can please suggest me doing wrong or there better way ?
after wasting lot of time thing helpful you.just use
@using (html.beginform("update", "profile", new { @id = "profileform" }, formmethod.post, new { @enctype = "multipart/form-data", }))
your id there new { @id = "profileform" }
Comments
Post a Comment