将两个参数从URL传递到MVC Controller [英] Passing two parameters from URL into MVC Controller
本文介绍了将两个参数从URL传递到MVC Controller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我有一个Windows应用程序,它有一个链接,当点击它时,它会向MVC应用程序发送两个参数,并且都需要显示。这些参数在URL上如下:
Hi All
I have a windows application that has a link that when clicked it sends two parameters to an MVC application and both need to display. These parameters are on the URL like this :
http://localhost:49224/?Name=L%20Dube&Employee=ANAR3701
当我接受我的MVC应用程序上的参数时,Employee参数为NULL,但Name确实有一个值,我不知道为什么会这样。当我接受参数时,我使用一个会话,这样我就不会丢失这个值。以下是我的操作方法:
When I accept the parameters on my MVC application the Employee parameter is NULL but the Name does have a value and I am not sure why this is. When I accept the parameters I use a session so that I do not lose the value. Below is my action method:
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();
}
推荐答案
请指定控制器和ActionResult,然后尝试
http:// localhost:49224 / Controller / Action?Name = L%20Dube& Employee = ANAR3701 [ ^ ]
希望这有助于
Please Specify the controller and ActionResult and then Try
http://localhost:49224/Controller/Action?Name=L%20Dube&Employee=ANAR3701[^]
Hope this helps
这篇关于将两个参数从URL传递到MVC Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文