asp.net-mvc-3 – 有没有办法通过html.actionlink在ASP.NET MVC 3中传递整个模型?

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-3 – 有没有办法通过html.actionlink在ASP.NET MVC 3中传递整个模型?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何通过html.actionlink传递整个模型或使用除表单提交之外的任何其他方法?有什么办法吗?

解决方法

虽然在复杂的情况下不可取,但您仍然可以做到这一点!
  1. public class Queryviewmodel
  2. {
  3. public string Search { get; set; }
  4. public string Category { get; set; }
  5. public int Page { get; set; }
  6. }
  7.  
  8. // just for testing
  9. @{
  10. var queryviewmodel = new Queryviewmodel
  11. {
  12. Search = "routing",Category = "mvc",Page = 23
  13. };
  14. }
  15.  
  16. @Html.ActionLink("Looking for something","SearchAction","SearchController"
  17. queryviewmodel,null);

这样就会产生一个与href的动作链接,

/ SearchController / SearchAction搜索=路由&安培;类别= MVC&安培;页= 23

这将是你的行动,

  1. public ViewResult SearchAction(Queryviewmodel query)
  2. {
  3. ...
  4. }

猜你在找的asp.Net相关文章