0

I am trying to send my model back to the controller with 2 values retrieved from a map control. I figured the best solution would be to put these values in a hidden input 'Html.hiddenfor()' so the controller receives the values in the model.

This is my JavaScript

endDragDetails = function (e) {
    alert("Event Info - start drag \n" + "Start Latitude/Longitude: " + e.entity.getLocation());
    var locationx = e.entity.getLocation();
    alert(locationx.latitude);
    document.getElementById("longitude").value = parseFloat(locationx.longitude);
}

The alertboxes show me there is a floating point value in the locationx var. I've tried passing it with the parseFloat() function In case the floating point number is actually a string. The id of longitude is indeed "longitude", I checked that in the html source.

this is my cshtml part

@Html.HiddenFor(m => m.longitude);

All I'm getting back is a 0,0. Am I missing something in this solution?

UPDATE If I change the hiddenfor with @Html.TextBoxFor(m => m.longitude) it displays the longitude in my textbox after executing the javascript method. However it does not send it to the controller, the value remains 0,0. It does however send all my other values like for example first name string, ... to the controller.

1 Answer 1

2

I've just done a quick check with what you're doing and it all seems ok. However, I'm a bit dubious of the value which you are getting from the locationx.longitude as you can't parse 0,0 or similar as a float. And you shouldn't need to when assigning to the hidden field as it handles it as a string anyway.

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

1 Comment

Thanks for your reply West. I fixed the problem. It had to do with my CurrentUICulture which is NL. I Changed it to EN and it works perfectly. In NL floating point numbers are written like this 5,34 in EN UIculture the are writtin like this 5.34. The UICulture did not affect the Model, that's a new challenge.

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.