0

When I have a strongly typed model like so

@model Person.Models.Person

Can I access the values in jQuery?

Furthermore, if I have an input like this, and it is edited, is the value stored in my model also changed?

<input type="text" class="form-control" value="@Model.FirstName" id="FirstName" placeholder="First Name">

I'm new to MVC, so I don't really understand this @model

My sincere thanks for your answers

Zach Johanson
  • 91
  • 1
  • 1
  • 5
  • I strongly suggest reading some basic tutorials first, [http://www.asp.net/mvc](http://www.asp.net/mvc) for example. – Zabavsky Feb 13 '15 at 09:00
  • yes, you can access the values from jquery, this post might help you on that: http://stackoverflow.com/questions/16361364/accessing-mvcs-model-property-from-javascript – Panda Zhang Feb 13 '15 at 09:52
  • You can assign a model property to a javascript variable using `var firstName = '@Model.FirstName';` but its the initial value of the model. If you want to access the edited value then you need to access the value of the control - `var firstName = $('#FirstName').val();` –  Feb 13 '15 at 10:09

1 Answers1

0

yes you can access all model values in jquery.

<script>
$(document).ready(function () { 
    var name=@Model.name;
    //or
    alert(@Model.msg);
});

vicky
  • 1,546
  • 1
  • 18
  • 35