0

I have an MVC multilingual application. I am trying to post value like 1,20 with decimal data type textbox in es-AR culture from a view with MVC form. My validation is working perfect as expected But when I try to post to MVC controller with value as mentioned it doesn't works. If I try to post a value like 1,200 it works perfectly. I am using http://ajax.aspnetcdn.com/ajax/jQuery.Validate/1.6/localization/messages_de.js for validation. Can any body help me to find a solution

UDATED

My MVC view

    @model BuyCreditViewModel
         @using (Ajax.BeginForm("SomeActionName", "SomeControllerName", null, new AjaxOptions()
            {
                HttpMethod = "POST",
                UpdateTargetId = "divPaymentProvider",
                OnBegin = "OnBegin",
                OnSuccess = "OnSuccess",
                OnFailure = "OnError"
            }, new { id = "frmPostAmt"}))
        {
        <div class="multy_form_holder">
                        <div class="multy_title">Amount</div>
                        <div class="multy_inputholder">
                            @Html.TextBoxFor(model => model.Cost, new { id = "txtAmount", @class = "multy_singleline" })
                        </div>
                        <div class="multy_validate_holder">@Html.ValidationMessageFor(model => model.Cost)<span id="lblCost"></span></div>
                        <div class="clear"></div>
                    </div>
        }

// To validate the text box with decimal data type using methods_de.js
<script type="text/javascript">
$(document).ready(function () {
 $("#frmPostAmt").validate();
}

My ViewModel

public class BuyCreditViewModel
{
 [Required]
 public decimal? Cost { get; set; }
}

My Controller

[HttpPost]
public ActionResult SomeActionName(BuyCreditViewModel accountViewModel)
{
      //TO Code
}
Jayaraj.K
  • 928
  • 9
  • 30
  • Can you copy-paste some code? Have you tried to snoop your HTTP POST with Fiddler? – CuriousSuperhero Jul 31 '15 at 10:35
  • Yes. I have tried. If I try to post 1,20 the request it will not respond , If you try to input like 1,200 worked for me – Jayaraj.K Jul 31 '15 at 11:46
  • Have you tried 1.20? 1,200 is not a decimal. – CuriousSuperhero Jul 31 '15 at 11:48
  • In Spanish 1,20 is meant for 1.20 – Jayaraj.K Jul 31 '15 at 11:50
  • What is the culture on your server (is it ES-AR)? –  Jul 31 '15 at 12:16
  • We have a language selection dropdown in our application .Culture changes according to the selection – Jayaraj.K Jul 31 '15 at 12:23
  • No, I mean what is the the server culture when you POST. If its not `ES-AR` or a culture that has the decimal separator as a comma, then binding will fail. –  Jul 31 '15 at 12:26
  • Server culture is EN-AU. – Jayaraj.K Jul 31 '15 at 12:35
  • @Jayaraj.K, That's Australian, which has a dot as the decimal separator. You need to change the server culture to `ES-AR` (or another culture that accepts comma), or create a custom model binder to handle this. –  Jul 31 '15 at 12:47
  • I have tried with custom model binder. It didn't work for me . And @Stephen is the server culture an issue . It is a doubt from me, Sorry if I have asked anything wrong. – Jayaraj.K Jul 31 '15 at 12:54
  • @Jayaraj.K, Yes the server culture is an issue. The `DefaultModelBinder` uses the servers current culture to parse the posted value to a `decimal` (using `TryParse` If you change it to `ES-AR` it should work fine. A custom `ModelBinder` will also work fine (if done correctly) –  Jul 31 '15 at 12:58
  • The problem is the form doesn't get submitted, nothing happens when I click the submit button when `1,2` is entered and focus jumps to this text box, though the textbox has `valid` class and `$("#form-id").valid()` returns true. – Jayaraj.K Jul 31 '15 at 13:33
  • @Jayaraj.K, What happens when you enter `1.2` instead of `1,2`? –  Jul 31 '15 at 13:38
  • If I enter 1.2 the I can throw a request to "SomeActionName", But if I enter 1,2 then I doesn't. – Jayaraj.K Aug 03 '15 at 06:12
  • Thanks @LeftyX: Refer my post http://stackoverflow.com/questions/32586551/what-is-the-best-way-to-handle-validation-with-different-culture – Jayaraj.K Oct 22 '15 at 04:22

0 Answers0