如何从视图将多个参数传递给操作方法

时间:2022-11-09 07:24:53

i'm doing something like this in category.cshtml view page

我在分类中做了类似的事情。cshtml视图页面

<select onchange="location = this.value;">
            <option value="/product/categoryByPage/id=@Model.CategoryID,limit=15" selected="selected">15</option>
            <option value="/product/categoryByPage/id=@Model.CategoryID,limit=30"
selected="selected">30</option>
            <option value="/product/categoryByPage/id=@Model.CategoryID,limit=50"
selected="selected">50</option>
    </select>

and from controller :

从控制器:

[ActionName("categoryByPage")]
 public ViewResult Category(Guid id, string limit)
 {
       Category cat = db.Categories.Find(id);
       return View(cat);
 }

but it isn't working and controller method unable to fetch that parameters ...

但是它不起作用,控制器方法无法获取那个参数……

thanks in advance,

提前谢谢,

Milan

米兰

1 个解决方案

#1


1  

you need to change your url as follows to work with default routing:

您需要更改您的url如下以使用默认路由:

<option value="/product/categoryByPage/@Model.CategoryID?limit=50"
selected="selected">

Note that id is actually in the default route as the last argument, any extra parameters you need need to be provided in query string format

注意,id实际上是在默认路由中作为最后一个参数,您需要的任何额外参数都需要以查询字符串格式提供。

#1


1  

you need to change your url as follows to work with default routing:

您需要更改您的url如下以使用默认路由:

<option value="/product/categoryByPage/@Model.CategoryID?limit=50"
selected="selected">

Note that id is actually in the default route as the last argument, any extra parameters you need need to be provided in query string format

注意,id实际上是在默认路由中作为最后一个参数,您需要的任何额外参数都需要以查询字符串格式提供。