传递多个参数到控制器? [英] Passing multiple parameters to a controller?

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

问题描述

确定。简单的一个是环绕我的大脑

ok. simple one that is wrapping my brain

我有,我有一个控制器中的方法

I have a method that I have in the controller

public ActionResult Details(string strFirstName, string strLastName)
{
      return View(repository.getListByFirstNameSurname(strFirstName, strLastName)
}

我如何获得多个参数,从URL到控制器?

How do i get multiple parameters from the URL to the controller?

我不希望使用的查询字符串,因为它似乎是不可MVC的思维定势。

I dont want to use the QueryString as it seems to be non-mvc mind set.

是否有路由?或其他机制,使这项工作?还是我失去了一些东西altogehter这里与MVC

Is there a Route? Or Other mechanism to make this work? Or am I missing something altogehter here with MVC

修改

这是我想要的网址是

http://site.com/search/details/FirstName and Surname

因此​​,如果这是传统的ASP

so if this was classic asp

http://site.com/search/details?FirstName+Surname

但我觉得我已经错过了了解一些东西,我匆忙去工作code,我已经错过了点,真的应该在一个PUT请求 - 我应该从的FormCollection收集这些

But i feel that i have missed understood something which in my haste to get to working code, I have missed the point that there really should be in a put request - and I should collect this from the formcollection.

虽然可能是值得看是否可以做到这一点 - 以供将来参考=>

Though might be worth while seeing if this can be done - for future reference =>

推荐答案

在您的形式使用隐藏值

<%= Html.Hidden("strFirstName", Model.FirstName)%>
<%= Html.Hidden("strLastName", Model.LastName)%>

和模型绑定会做结合

public ActionResult Details(string strFirstName, string strLastName)
{
      return View(repository.getListByFirstNameSurname(strFirstName, strLastName)
}

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

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