比方說你有一個對象通JSON上的Response.Redirect
public class SomeViewModel
{
public SomeViewModel()
{
this.SomeData = new List<SomeData>();
}
public string Name { get; set; }
public string Surname{ get; set; }
public List<SomeData> SomeData { get; set; }
}
public class SomeData
{
public string Name { get; set; }
public string Value { get; set; }
}
,現在我想給模型傳遞從ASP.NET應用程序查詢字符串到ASP.NET MVC應用程序
string json = JsonConvert.SerializeObject(someModelVM);
//how to convert it to querystring ?
Response.Redirect("http://somedomain.com/SomeAction?redirect=" + querystring, true);
所以重定向後會綁定正確
public ActionResult SomeAction(SomeViewModel someViewModel)
{
//do something here
}
UPDATE
我選擇了簡單的解決方案,而不是複雜化。
string json = JsonConvert.SerializeObject(someModelVM);
Response.Redirect("http://somedomain.com/SomeAction?redirect=" + json, true);
public ActionResult SomeAction(string json)
{
//try to deserialize json
//security check the json
//do stuff
}
請記住,瀏覽器使用「GET」方法可以通過HTTP發送多少數據的限制。 – Matthew 2013-02-13 01:48:43
謝謝,我知道。 – 2013-02-13 02:07:56