模型对象上设置的财产? [英] Setting property on the model object?

查看:107
本文介绍了模型对象上设置的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个ASP.NET MVC的网站和整个问题都拼命地跑。在我的项目我有一个包含一些属性的模型视图类,例如:

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;}
}

此模型视图类势必会,我需要比布尔设置的属性类型的视图。我如何做到这一点的JavaScript / jQuery的?我曾尝试与Model.MyProperty1 = 1,但不起作用?

This modelview class is bound to a typed view where I need to beable 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

推荐答案

您不能用JavaScript设置服务器端的值。你可以结合这些值来使用HTML助手,然后使用JavaScript可以修改这些输入字段的值输入字段(文本框,隐藏域,文字区域,下拉菜单,...)。

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.

这篇关于模型对象上设置的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆