所以正确的是,我想用Html.ActionLink调用一个控制器方法,就像我在其他ocasions中所做的一样,只有这一次,我给它一个本身包含另一个对象和一个字符串的对象。但该对象始终为空。我保持登录ViewBag(它在那里,我检查)。使用Html.ActionLink与复杂的对象(包含与其他对象)
的类:
public class Login
{
[Required(ErrorMessage = "Username is required")] // make the field required
[Display(Name = "Username")] // Set the display name of the field
public string Username{ get; set; }
[Required(ErrorMessage = "Password is required")]
[Display(Name = "Password")]
public string Password{ get; set; }
[Required(ErrorMessage = "Company is required")]
[Display(Name = "Company")]
public string Company{ get; set; }
}
public class Filter
{
public Login loginInfo;
public string idDocument;
}
的Html.ActionLink调用:
@Html.ActionLink("Details", "DetailOrder", "Home", new {loginInfo = new { Company = ViewBag.loginInfo.Company, Username = ViewBag.loginInfo.Username, Password = ViewBag.loginInfo.Password }, idDocument = @Html.DisplayFor(modelItem => item.NumDoc) }, htmlAttributes:null)
控制器方法
public ViewResult DetailOrder(Filter afilter)
{
...
return View(ans);
}
在这一点上,我已经尝试了一些东西,动作链接,通过给对象:
2-new { loginInfo=ViewBag.loginInfo, idDocument= @Html.DisplayFor(modelItem => item.NumDoc)}
3-new { Username=ViewBag.loginInfo.Username, Password=ViewBag.loginInfo.Password, Company=ViewBag.loginInfo.Company, idDocument= @Html.DisplayFor(modelItem => item.NumDoc)}
4-new { afilter = new {loginInfo=ViewBag.loginInfo, idDocument= @Html.DisplayFor(modelItem => item.NumDoc)} }
我使它通过改变控制器方法头的工作:
public ViewResult DetailOrder(Login loginInfo, string idDocument)
,然后使用在ActionLink的所述NR3对象组合物。但是这不是可重复使用的编码...我现在真的很想知道如何将ActionLink用于复杂的对象。它甚至有可能吗?我还没有在ms教程中找到一个例子。
感谢
该框架是为了把一个HTTP请求'?a = 1&b = 2&c = 3'成.NET可以理解的东西。我不明白为什么这应该是可能的 – beautifulcoder 2014-12-04 22:11:43
你是否在查询字符串中传递真实密码?如果您已经拥有这些属性,为什么不将它们存储在某个存储或会话中? – 2014-12-04 22:17:20
@VsevolodGoloviznin我正在使用休息架构,这是我找到的方式,所以我不需要在服务器端控制它。 – 2014-12-04 22:37:06