So I am looking to solve what I have found to be a pretty particular issue. Essentially I have models in Microsoft MVC that have decimal fields. I am to display these fields in views with masking on them that includes commas (money values separated by hundreds). Essentially the problem is that I need to display the comma version and let users edit them, but when I post the values back to server I need to strip the commas. I have looked into a range of options including the jquery autonumeric plugin (which has a get method that returns the unformatted value, but unsure how to get the values back into the models on post), as well as dabbled with stripping the values of commas via jquery before they are submitted back to server (but I read that this isn't always guaranteed as sometimes the values can be posted back before the jquery is done. So here is what I am doing to give some context:
My actual model classes are similar to this, only instead of one there are about 50 fields per class:
public class classtest
{
public decimal v { get; set; }
}
I'm doing nothing special in the controllers, I have a method passing the model to the view, and then another post method that has the model as a parameter in which I am using that model to save back to the database.
@model MvcApplication1.Models.classtest
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm("Index", "Test", FormMethod.Post))
{
@Html.TextBoxFor(t => t.v, new { @class = "money" })
<input type="submit" name="submit" value="Submit" />
}
Any advice would be appreciated.