How to send a dictionary parameter to a URL.Action() in asp.net MVC3 -
say have action method.......
public actionresult displayxml(int viewid, dictionary<string,string> parameter, string dataformat ) { string xml = ""; return content(xml, "text/xml"); }
and in view did.......
<iframe title="xml" class="resultdisplay" src = "@url.action("displayxml", "outputdata", new {viewid = model.viewid, parameter = model.parameter, dataformat = model.dataformat })"> </iframe>
here parameter dictionary , getting null. how can send it?????
you're trying pass , arbitrary dictionary parameter in querystring?
its pretty unusual requirement need serialize contents of dictionary query string parameter , again. when generating querystring parameters, mvc call .tostring() on values, , dictionary<,> object uses default implementation (which returns it's type)
since requirement uncommon, there's nothing built in this.. can quite serialize dictionary string (perhaps json?) , then, change parameter variable in action string. you'll have deserialize value dictionary after that.
before provide more of example, want check you're absolutely sure want do
update:
here way of doing (requires json.net):
public actionresult displayxml(int viewid, string parameterjson, string dataformat ) { var parameter = jsonconvert.deserializeobject<dictionary<string,string>>(parameterjson); string xml = ""; return content(xml, "text/xml"); }
and use:
<iframe title="xml" class="resultdisplay" src = "@url.action("displayxml", "outputdata", new {viewid = model.viewid, parameterjson = newtonsoft.json.jsonconvert.serializeobject(model.parameter), dataformat = model.dataformat })"> </iframe>
Comments
Post a Comment