-1

I have TextboxFor in partial view,I want to display decimal format example( 3,108,000.00). is work for display but want i call controller by Ajax value is be null. thank for help.

@Html.TextBoxFor(x => x.List_TRNQuotationLeasing.CashBook, new { @class = "numeric form-control right", @Value = Model.List_TRNQuotationLeasing.CashBook != null ? Model.List_TRNQuotationLeasing.CashBook.Value.ToString("#,##0.00") : "" })

enter image description here

enter image description here

3
  • Could you put your Ajax' code? Commented Feb 9, 2018 at 8:24
  • Can you submit the value as smallest value and then process it server side? So for instance if the value was in GBP and it was 3,108,000.00, you would submit 310800000 - which is 3,108,000.00 * 100 to put it in pence. You would then divide that value on the server by 100 to get the original value Commented Feb 9, 2018 at 9:20
  • Otherwise you could go down the custom model binder route - which may be a bit overkill - stackoverflow.com/questions/37389084/… Commented Feb 9, 2018 at 9:21

1 Answer 1

0

You cannot post a value like 900,000.00 directly to decimal, if you're trying to do that. You need to reformat the number and get rid of the , before sending, use string in the ViewModel and apply convertion after posting, or use a special ASP.NET MVC Model Binder to do that conversion during the Request.

If you want to go with Option 1 for example, you could do this in JavaScript just before sending (jQuery):

 // ...before send...
 // e.g. apply to all fields marked with "numeric"
 $("input.numeric").each(function() {
    numericWithOutComma = $(this).val().replace(",", "");

    // override text... yes it will lose the format. You could enhance that later
    $(this).val(numericWithOutComma);
 });

 // Execute Ajax send...

Also, there is this interesting discussion about that if you want to go with Option 3, for example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.