[英]How to change a model property from a javascript function inside a view?
Is there any way to alter my Model properties from a javascript function inside a view? 有没有办法从视图中的javascript函数改变我的模型属性?
Specifically, I have an edit view and need to access a string property value with 具体来说,我有一个编辑视图,需要访问字符串属性值
function SomeJSFunction() { function SomeJSFunction(){
var somevar = '<%=Model.Property %>'; var somevar ='<%= Model.Property%>';
... ...
then do some changes on somevar and set the model property to the changed string. 然后对somevar进行一些更改并将model属性设置为更改的字符串。 I'm doing a submit at this point, so it's not a question of dealing with the display, just need to alter the model from inside the function before I submit. 我现在正在提交,所以这不是处理显示的问题,只需要在我提交之前从函数内部改变模型。 I know I could pass the string as a parameter and deal with it inside the controller but it just doesn't cut it as I really need to be done with it in the view. 我知道我可以将字符串作为参数传递并在控制器内处理它但它只是没有剪切它,因为我真的需要在视图中完成它。 Appreciate any help! 感谢任何帮助!
You can't do this using javascript. 你不能用javascript做到这一点。 The model is instantiated by the controller and passed to the view. 该模型由控制器实例化并传递给视图。 If you want to modify some properties you will need to perform a request to a controller action and send the new values. 如果要修改某些属性,则需要对控制器操作执行请求并发送新值。 This could be done either using a standard form or AJAX request. 这可以使用标准表单或AJAX请求来完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.