New to MVC, trying to pass a variable from Flash using FSCommand (works well with other functions) from one view to another. The Javascript I am using:
function p1_DoFSCommand(command, args) {
var p1Obj = InternetExplorer ? p1 : document.p1;
if (command == "nameClip") {
var FlashName = [args];
}
in the Homecontroller:
public ActionResult Testing(string FlashName)
{
ViewData["Message"] = FlashName;
return View();
}
In the second view:
Html.Encode(ViewData["message"])
Would appreciate your assistance.
This should get the data to the Action method:
You’ll also need to reference jQuery for this to work.
If you need to pass that value to another controller, simply change
to
edit:
I’m not sure exactly what you’re trying to do, but ViewData is a data construct that only has relevance in the Controller and when the View is being executed. By the time the JavaScript is running, it’s in the context of a rendered page, so ViewData is meaningless. If, in your view you had
<input id='MyMessage' type='hidden' value='<%=(string)ViewData['Message'] %>' />,you could then get the value you’re looking for with
or