asp.net mvc - Parse all values from a textbox in a method using javascript before sending to the controller -
i have static method here:
public static string parsestringforspecialchars(string stringtoparse) { const string regexitem = "[^a-za-z0-9 ]"; string stringtoreturn = regex.replace(stringtoparse, regexitem, @"\$%&'"); return stringtoreturn; }
this method works fine stops many strings being harmful application. suppose there's better way things, that's not point of post.
right want values any textboxes in javascript call method , send data controller.
say have view:
@using myapp.utilities @model list<myapp.models.customerobj> @{ viewbag.title = "customer index"; } <h2>customer index</h2> <p> @html.actionlink("create new", "create") @using (html.beginform()) { <p> name: @html.textbox("customername") <br/> address: @html.textbox("customeraddress") city: @html.textbox("customercity") <br/> <br /> postal code: @html.textbox("customerpc")<br/> phone number: @html.textbox("customerphone") fax number: @html.textbox("customerfax")<br /> mail: @html.textbox("customeremail") <br/> <input type="submit" value="filter" style="float:right"> </p> } </p>
how proceed want do? can offers me suggestion how proceed? flexible workaround since view have right change , need method appliable everywhere.
thank you.
have considered adding data annotation model this:
[regularexpression(@"^\$?\d+(\.(\d{2}))?$")]
this captured from: http://www.asp.net/mvc/tutorials/older-versions/models-%28data%29/validation-with-the-data-annotation-validators-cs
of course, downside have add properties in model want apply to. might able use remote validation , fire off via javascript. otherwise, stuck doing on client side. (but that's not difficult anyway.)
Comments
Post a Comment