如何在mvc中调用javascript函数形式控制器动作 [英] how to call javascript function form controller action in mvc

查看:72
本文介绍了如何在mvc中调用javascript函数形式控制器动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我可以从MVC控制器操作(而不是从视图页面)调用javascript函数并获取返回值吗?怎么样?

谢谢

Hi,
Can I call javascript function from MVC controller action (not from view page) and get return value? How?

Thank You

推荐答案

嘿!

您的MVC控制器通常在服务器端,而javascript在客户端运行.如果要将值从一个传递到另一个,则必须发布该值(例如,使用查询字符串).运行MVC控制器方法时,无法访问javascript函数.

例如,您可能要使用具有隐藏字段的表单并提交表单,该隐藏字段的值将被传递到可访问的服务器.

祝你好运!

爱德华
Hey!

Your MVC controller is typically server side, where javascript runs client side. If you want to pass a value from one to another you have to post the value (for example using a querystring). You cannot access a javascript function while running a MVC Controller method.

You may want to use for example a form with a hidden field and submit the form, the value of the hidden field will be passed to the server where is will be accessible.

Good luck!

Eduard


这篇关于如何在mvc中调用javascript函数形式控制器动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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