带有 ActionNames 的 T4MVC
我刚刚将 T4MVC 包含在我的项目中并遇到了问题。我通过隐藏文本字段将数据传递到我的 javascript,并且我需要能够传递控制器的名称及其操作。这就是我所拥有的:
<input type="hidden" id="logErrorUrl" name="logErrorUrl" value="@Url.Action("LogJavaScriptError", "Error") />
我希望能够做到:
<input type="hidden" id="logErrorUrl" name="logErrorUrl" value="@Url.Action(MVC.Error.LogJavaScriptError("")) />
由于某种原因,这不起作用。我在想是因为 LogJavascriptError 不返回 ActionResult。仅供参考 LogJavaScriptError 也接受一个字符串,但我真的只想要操作的名称。我还尝试了 @MVC.Error.ActionNames.LogJavaScriptError 但它可能不会再次出现,因为它不返回 ActionResult?
I just included T4MVC in my project and ran into an issue. I'm passing data to my javascript via hidden text fields and I need to be able to pass the names of controllers and their actions. Here's what I have:
<input type="hidden" id="logErrorUrl" name="logErrorUrl" value="@Url.Action("LogJavaScriptError", "Error") />
I'd like to be able to do:
<input type="hidden" id="logErrorUrl" name="logErrorUrl" value="@Url.Action(MVC.Error.LogJavaScriptError("")) />
For some reason this isn't working. I was thinking because LogJavascriptError doesn't return an ActionResult. FYI LogJavaScriptError also takes in a string but I really just want the name of the action. I also tried @MVC.Error.ActionNames.LogJavaScriptError but it doesn't show up perhaps again because it doesn't return an ActionResult?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
T4MVC 仅适用于返回 ActionResult 的操作方法。如果您的方法不需要返回任何内容,那么建议的做法是返回 EmptyResult,例如
T4MVC only works with action methods that return an ActionResult. If your method doesn't need to return anything, then the recommended thing to do is to return an EmptyResult, e.g.