Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
45
rated 0 times [  51] [ 6]  / answers: 1 / hits: 34401  / 14 Years ago, thu, march 3, 2011, 12:00:00

Hi,



I am building a ASP.NET MVC site and have runned across a problem. In my project I got a modelview class that contains a couple of properties, for example :



public class myModelView
{
public int MyProperty1(){ get; set;}
public int MyProperty2(){ get; set;}
public int MyProperty3(){ get; set;}
}


This modelview class is bound to a typed view where I need to be able to set the properties. How do I do this with javascript/jquery? I have tried with Model.MyProperty1 = 1, but that does not work?



BestRegards


More From » jquery

 Answers
10

You cannot set server side values with javascript. You could bind those values to input fields (textboxes, hidden fields, textareas, dropdowns, ...) using HTML helpers and then using javascript you could modify the values of those input fields.



So for example if you have a hidden field:



<input type=hidden name=foo id=foo value=bar />


you could modify its value like this:



$('#foo').val('some new value');


Then when the containing form is submitted to the server the new value will be bound to your view model.


[#93468] Wednesday, March 2, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ramiro

Total Points: 431
Total Questions: 96
Total Answers: 105

Location: Northern Ireland
Member since Mon, Nov 14, 2022
2 Years ago
ramiro questions
Thu, May 7, 20, 00:00, 4 Years ago
Tue, Apr 28, 20, 00:00, 4 Years ago
Sun, Feb 16, 20, 00:00, 4 Years ago
;