I have an action
[HttpGet]
public ActionResult Index(MyObject obj)
{
return View(obj);
}
and an object:
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class MyObject
{
[JsonProperty(PropertyName = "someString")]
public String SomeString
{
get { return _someString; }
set { _someString = value; }
}
[JsonProperty(PropertyName = "someDictionary")]
public IDictionary SomeDictionary
{
get { return _someDictionary; }
set { _someDictionary = value; }
}
public MyObject()
{
}
private String _someString;
private IDictionary _someDictionary;
}
I want to pass this object to action by url. So I create url:
String url = controller.Url.Action("Index", "SomeController");
url += "?obj=" + JsonConvert.SerializeObject(myObjectInstance);
It's create me an url with json, but when I use it - the object in url is null.
Can anybody help me?
Thanks!
UPDATED: Share instance of my MyObject as reaction to comments:
MyObject myObjectInstance = new MyObject ();
myObjectInstance.SomeString = "Hello";
myObjectInstance.SomeDictionary = new Dictionary<String, Object>
{
{"firstKey","value"},
{"secondValue",5}
}