How can I set a value to my model using jQuery?
I have an input field (which its id=”comment”) and I want the text in it to be inserted into @Model.Comment
using jQuery.
something like: @Model.Comment = $("#comment").val();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This doesn’t make any sense. jQuery runs on the client. The Model lives on the server. So by the time jQuery executes on the client, the server side code and the Model is long dead.
What you could do from the client is send an AJAX request to the server passing it the value of the input field so that the server can take respective actions and update the model:
Where on the server you will have a Foo controller action that will be invoked: