如何在mvc视图中重定向到操作 [英] How do I redirect to action in mvc view

查看:54
本文介绍了如何在mvc视图中重定向到操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我有一点问题,经验丰富的MVC专业人员可能看起来很傻但是在过去几年我在Web Forms编程后对MVC很新。好吧我的问题,我有一个强类型视图,显示我的模型列表,显示在网格中。每当用户单击网格中的一个按钮时,我希望能够巧妙地重定向到我的控制器的编辑操作。我试过在Jquery和视图中做过但我没有运气。



查看

 <  按钮   类型  = 按钮    id   = 编辑   名称  =' 编辑'    onclick   =  window.location.href('@ Url.Action(  Edit ,帐户)') >  <   / button  >  





控制器

  public  ActionResult Edit()
{
return View();
}





因此以下代码无效。我只需要知道重定向到Edit操作的正确方法。在此先感谢您的帮助。

解决方案

您应该从这样的视图中更改您的代码;

 <  按钮    type   =  button    id   = 编辑    名称  =' < span class =code-keyword>编辑'    onclick   =  self.location ='@ Url.Action( 编辑,帐户)' >  <   / button  >  


Hey guys, I have a little problem which to seasoned MVC pros might seem silly but I'm pretty new to MVC after programming in Web Forms for the last couple of years. Ok my problem, I have a strongly typed view which displays a list of my Models which is displayed in a grid. I want to be ably to redirect to my "Edit" action of my controller whenever the user clicks one of the buttons in the grid. I have tried doing in both Jquery and in the view but I'm having no luck.

View

<button type="button" id="Edit" name='Edit' onclick="window.location.href('@Url.Action("Edit","Account")')"></button>



Controller

public ActionResult Edit()
       {
           return View();
       }



So the below code is not working. I just need to know the correct way to redirect to the Edit action. Thanks in advance for your help.

解决方案

You should change your code from the view like this;

<button type="button" id="Edit" name='Edit' onclick="self.location='@Url.Action("Edit","Account")'"></button>


这篇关于如何在mvc视图中重定向到操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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