0

I want to display an alert message like follows

alert('' + @Model.DictionaryTest["alertInvalidTemplate"] + '');

but it does not work, I tried the following way too

alert(@Model.DictionaryTest["alertInvalidTemplate"]);

and this too

alert("" + @Model.DictionaryTest["alertInvalidTemplate"] + "");
2
  • the alertInvalidTemplate is your key or value? Commented Jun 26, 2019 at 5:14
  • you should write a function like this $.each(Mydata, function(key, val){ // This function will called for each key-val pair. // You can do anything here with them. }); Commented Jun 26, 2019 at 5:16

1 Answer 1

1

This should work:

alert('@Model.DictionaryTest["alertInvalidTemplate"]');

Otherwise, you can create hidden, which will hold that value, then get that from JS and show with alert.

View:

@Html.HiddenFor(h => h.DictionaryTest["alertInvalidTemplate"])

JS:

alert($("#DictionaryTest_alertInvalidTemplate_").val());

Notice that in this case, the id of hidden input will become DictionaryName_Key_ (if you do not specify it manually).

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.