2

I have code like following

    function AddValidation() {
            var [email protected](Configuration.DistanceUOM);

            $("#km").rules('add', { chekrule: ["#PerKm", "Cost Per " +distance +"should be positive."] });

}

I'm getting error for distance as undefined.

unable to get the proper value of @Utilities.getConfiguration(Configuration.DistanceUOM); in java script function

please correct me in syntax.

1
  • What does your rendered page source look like? Commented Nov 22, 2013 at 11:39

1 Answer 1

3

Now sure what kind of project you are using.

It could be

function AddValidation() {
            var distance="<%=ConfigurationManager.AppSettings["DistanceUOM"] %>";
            $("#km").rules('add', { chekrule: ["#PerKm", "Cost Per " +distance +"should be positive."] });

}

OR

function AddValidation() {
            var distance="@ConfigurationManager.AppSettings["DistanceUOM"]";
            $("#km").rules('add', { chekrule: ["#PerKm", "Cost Per " +distance +"should be positive."] });

}

depending on your mvc version.

Also you don't provide information what Utlilities is but if that code works in the code behind, it will also work on your view if you include the correct library at the top

<%@ Import Namespace="Ulities" %>

or

 @using Ulities

So if you include that library properly then you can use your thing:

function AddValidation() {
            var distance="<%= Utilities.getConfiguration(Configuration.DistanceUOM)%>";
            $("#km").rules('add', { chekrule: ["#PerKm", "Cost Per " +distance +"should be positive."] });

}

Can't help you more without knowledge of your project

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.