[英]Call a Javascript form within a controller in MVC4
I want to call a javascript function from within a controller function that I use: 我想从我使用的控制器函数中调用javascript函数:
Public Function redirectTo() As JavaScriptResult
Return JavaScript("ToSignUp()")
End Function
in my controller. 在我的控制器中。 But the program never goes to the script.
但是程序永远不会去脚本。 I've already checked similar answers but I haven't found any solution to the problem.
我已经检查过类似的答案,但是还没有找到解决问题的方法。 Can someone assist me with this?
有人可以协助我吗?
ADDITION 4/3/19 12:41 19/4/3/12 12:41
I use the following for redirection from my controller... but nothing is happening: 我将以下内容用于从我的控制器进行重定向...但是什么也没发生:
Public Function redirectTo() As RedirectToRouteResult
Dim routes As New RouteCollection With {.RouteExistingFiles = True}
Return RedirectToAction("../login/SignUp")
End Function
End Class
ADDITION 4/3/19 23:20 19/4/3/23 23:20
The issue was solved by this way 通过这种方式解决了问题
In the code behind
of my .aspx
Page and at the proper place I add it the following code: 在
.aspx
页面code behind
的code behind
,并在适当的位置添加以下代码:
Dim routes As New RouteCollection With {.RouteExistingFiles = True}
Response.Redirect("SignUp")
The Response.Redirect
instruction is not new. Response.Redirect
指令不是新的。
But in order to be functional it needs to add before the following instruction 但是为了发挥作用,需要在以下说明之前添加
Dim routes As New RouteCollection With {.RouteExistingFiles = True}
And that is because the MVC did not recognize the existent files which means the property RouteExistingFiles
is always False
这是因为MVC无法识别现有文件,这意味着
RouteExistingFiles
属性始终为False
Thus in order to work the code we need to turn this property to True
因此,为了工作代码,我们需要将此属性设置为
True
Anyway thanks to all for your assistance. 无论如何,感谢大家的帮助。
From other examples online ( like this one ), I would say that if you temporarily changed your function to: 从其他在线示例( 如本示例)中,我想说的是,如果您暂时将函数更改为:
Public Function redirectTo() As JavaScriptResult
Return JavaScript("alert("HERE");")
End Function
It will likely work... so without seeing the JS function contents, it's hard to tell. 它可能会工作...因此,如果看不到JS函数的内容,就很难说出来。 To the second point, a
RedirectToAction
call will work if called from the server; 第二点,如果从服务器调用,则
RedirectToAction
调用将起作用。 if the client is calling this, use 'window.location' instead. 如果客户端正在调用它,请改用“ window.location”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.