asp.net mvc - How to create MVC 4 @Html.TextBox type="file"? -
i need add following field @ form
<input type="file" class="input-file" /> i create model , describe field (the last field)
using system; using system.collections.generic; using system.linq; using system.web; namespace corepartners_site2.models { public class feedbackform { public string name { get; set; } public string email { get; set; } public string phone { get; set; } public string company { get; set; } public string additionalinformation { get; set; } public httppostedfilebase projectinformation { get; set; } } } and create
@html.textbox(null, null, new { type="file", @class="input-file" }) but doesnt work, exception. what's wrong?
model
public class feedbackform { public string name { get; set; } public string email { get; set; } public string phone { get; set; } public string company { get; set; } public string additionalinformation { get; set; } public httppostedfilebase projectinformation { get; set; } } view
@model feedbackform @html.textbox("name") @html.textbox("email") ... @html.textbox("projectinformation", null, new { type="file", @class="input-file" }) // submit button my recommended view (strongly - typed)
@model feedbackform @html.textboxfor(model=>model.name) @html.textboxfor(model=>model.email) ... @html.textboxfor(model=>model.projectinformation, null, new { type="file", @class="input-file" }) // submit button controller
[httppost] public actionresult feedbackform(feedbackform model) { // uploaded file var file = model.projectinformation; ... return view(); } mvc using name conversation, if use same variable names textbox model, mvc bind inputs model.
Comments
Post a Comment