将两个参数从URL传递到多个MVC控制器 [英] Passing two parameters from URL into more than one MVC Controller

查看:103
本文介绍了将两个参数从URL传递到多个MVC控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个Windows应用程序,点击时有一个链接,它会向MVC应用程序发送两个参数,并且都需要显示。参数在URL上如下:



http:// localhost:49224 / AbsaFlexi / Intro?名称= L%20Dube& Employee = PSHA2518



AbsaFlexi是我的控制器的名称,Intro是AbsaFlexi控制器中的ActionMethod。我想知道我是否可以使用另一个ActionMethod接受相同的参数显示在另一个View中而不指定上面提供的URL中的Controller和ActionMethod?下面是我在AbsaFlexi控制器中的Intro ActionMethod,它接受以下参数:



Hi All
I have a windows application that has a link when clicked it sends two parameters to an MVC application and both need to be displayed. The parameters are on the URL like this:

http://localhost:49224/AbsaFlexi/Intro?Name=L%20Dube&Employee=PSHA2518

AbsaFlexi is the name of my controller and Intro is the ActionMethod in the AbsaFlexi controller. I would like to know if I can use another ActionMethod to accept the same parameters to display in another View without specifying the Controller and ActionMethod in the URL provided above? Below is my Intro ActionMethod in the AbsaFlexi Controller which accepts the parameters:

public ActionResult Intro(string Name, string Employee)
       {
           if (!string.IsNullOrEmpty(Name) || !string.IsNullOrEmpty(Employee))
               Session["Name"] = Name;
               Session["Employee"] = Employee;

               string strName = string.Empty;
               string strEmployee = string.Empty;

                if (Session["Name"] != null)
                   strName = Session["Name"].ToString();
                if (Session ["Employee"] != null)
                   strEmployee = Session["Employee"].ToString();

           ViewBag.ClientFirstName = strName;
           ViewBag.Employee = strEmployee;


             return View();
       }

推荐答案

是的,可以添加另一个具有相同参数的actionmethod ..

您也可以从新的操作方法中设置另一个视图..
yes it is possible to add another actionmethod with same parameter..
Also u can set another view from the new action method..


这篇关于将两个参数从URL传递到多个MVC控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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