my model is
public class fileselectcontrol { //property selected file path value public string filepath { get; set; } } view
@html.fileboxfor(x => x.filepath) where fileboxfor custom html helper class returns html (with input tag)
problem statement : unable assign value in fileselect textbox property filepath. click on browse button of file upload control , , select file, file path value not updated filepath property.
here custom html helper
public static mvchtmlstring fileboxfor<tmodel, tvalue>(this htmlhelper<tmodel> htmlhelper, expression<func<tmodel, tvalue>> expression) { return htmlhelper.fileboxfor<tmodel, tvalue>(expression, (object)null); } /// <summary> /// returns file input element using specified html helper , name of form field expression. /// </summary> /// <typeparam name="tmodel">the type of model.</typeparam> /// <typeparam name="tvalue">the type of value.</typeparam> /// <param name="htmlhelper">the html helper instance method extends.</param> /// <param name="expression">the expression resolves name of form field , <see cref="system.web.mvc.viewdatadictionary" /> key used validation errors.</param> /// <param name="htmlattributes">an object contains html attributes element. attributes retrieved through reflection examining properties of object. object typically created using object initializer syntax.</param> /// <returns> /// input element has type attribute set "file". /// </returns> public static mvchtmlstring fileboxfor<tmodel, tvalue>(this htmlhelper<tmodel> htmlhelper, expression<func<tmodel, tvalue>> expression, object htmlattributes) { return htmlhelper.fileboxfor<tmodel, tvalue>(expression, new routevaluedictionary(htmlattributes)); } /// <summary> /// returns file input element using specified html helper , name of form field expression. /// </summary> /// <typeparam name="tmodel">the type of model.</typeparam> /// <typeparam name="tvalue">the type of value.</typeparam> /// <param name="htmlhelper">the html helper instance method extends.</param> /// <param name="expression">the expression resolves name of form field , <see cref="system.web.mvc.viewdatadictionary" /> key used validation errors.</param> /// <param name="htmlattributes">an object contains html attributes element. attributes retrieved through reflection examining properties of object. object typically created using object initializer syntax.</param> /// <returns> /// input element has type attribute set "file". /// </returns> public static mvchtmlstring fileboxfor<tmodel, tvalue>(this htmlhelper<tmodel> htmlhelper, expression<func<tmodel, tvalue>> expression, idictionary<string, object> htmlattributes) { var name = expressionhelper.getexpressiontext(expression); return htmlhelper.filebox(name, htmlattributes); }
Comments
Post a Comment