0

I have asp.net mvc4 project where on edit page I try to send value from model to jquery function as variable.

This code isn't work, nothing hit, does anybody know how can I get value from model without setting hidden properties.

Edit:

@model WebForTesting.Models.Form.ProfForm

<script>

    $(document).ready(function () {
        setOptionValue();
    });

    function setOptionValue() {
        alert('@(Model.ChildrenId)');
    }
</script>

I'm sure that ChildrenId isnt null

BorHunter
  • 893
  • 3
  • 18
  • 44

2 Answers2

0

Try this:

function setOptionValue() {
    alert("@(Model.ChildrenId)");
}
Paweł Bejger
  • 6,176
  • 21
  • 26
  • 2
    @BorHunter If it doesn't work are you positive your Model is filled? Are you getting any errors? What does the ViewSource look like at time of rendering? "It doesn't work" is an answer usually reserved for users. – Tony Jan 30 '14 at 19:38
0

Don't use $(document).ready(), see below:

<script>
    setOptionValue();
    function setOptionValue() {
        alert('@(Model.ChildrenId)');
    }
</script>
Lin
  • 15,078
  • 4
  • 47
  • 49