如何通过html.actionlink传递整个模型或使用除表单提交之外的任何其他方法?有什么办法吗?
解决方法
虽然在复杂的情况下不可取,但您仍然可以做到这一点!
- public class Queryviewmodel
- {
- public string Search { get; set; }
- public string Category { get; set; }
- public int Page { get; set; }
- }
- // just for testing
- @{
- var queryviewmodel = new Queryviewmodel
- {
- Search = "routing",Category = "mvc",Page = 23
- };
- }
- @Html.ActionLink("Looking for something","SearchAction","SearchController"
- queryviewmodel,null);
这样就会产生一个与href的动作链接,
/ SearchController / SearchAction搜索=路由&安培;类别= MVC&安培;页= 23
这将是你的行动,
- public ViewResult SearchAction(Queryviewmodel query)
- {
- ...
- }