ASP.NET MVC 中的操作

发布于 2024-08-08 21:40:09 字数 919 浏览 1 评论 0原文

输入我的网址时 SalaryFor/Microsoft/Balmer 我需要显示名为 Balmer 的用户的工资 如果我输入 URL 微软/微软的薪资 我需要显示微软公司所有员工的工资

可以吗? 因为当我使用这个链接时 SalaryFor/Microsoft/Balmer 一切正常,

public ActionResult Salary(string company, string person)

公司和个人都包含价值观

,但此链接不起作用 SalaryFor/Microsoft

public ActionResult SalaryFor(string company, string person)

两个值都包含 null

我在 global.asax 中的路线是

    routes.MapRoute("Salary",
                    "{controller}/{action}/{company}/{position}",
                    new
                        {
                            controller = "Salary",
                            action = "SalaryFor",
                            company = "",
                            test = ""
                        });

O 也许我做错了什么? 谢谢, 亚历山大.

When typing in my URL
SalaryFor/Microsoft/Balmer
i need to display salary for user with name Balmer
and if I type in URL
SalaryFor/Microsoft
i need to display salary for all employee in Microsoft company

Is it possible?
because when I use this link
SalaryFor/Microsoft/Balmer
all works fine

public ActionResult Salary(string company, string person)

both company and person contains values

but this link does not work
SalaryFor/Microsoft

public ActionResult SalaryFor(string company, string person)

both values contains null

my route in global.asax is

    routes.MapRoute("Salary",
                    "{controller}/{action}/{company}/{position}",
                    new
                        {
                            controller = "Salary",
                            action = "SalaryFor",
                            company = "",
                            test = ""
                        });

O maybe I am making something wrong?
Thanks,
Alexander.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

写下不归期 2024-08-15 21:40:09

您需要绘制第二条路线。

routes.MapRoute("Salary2",
                    "{controller}/{action}/{company}",
                    new
                        {
                            controller = "Salary",
                            action = "SalaryFor",
                            company = ""
                        });

You need to map a second route.

routes.MapRoute("Salary2",
                    "{controller}/{action}/{company}",
                    new
                        {
                            controller = "Salary",
                            action = "SalaryFor",
                            company = ""
                        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文