I am developing an MVC3 application using C# and Razor. I have a problem when I need to display one the Play View.
The Play action method is used to retrieve a path of a FLV (Flash) file to be then passed to the Play View to reproduce the file.
When I use return View("Play")
the application renders the View correctly. However I need to pass the path variable to the View as shown in the code. When I do it I receive the following message:
The view 'Play' or its master was not found or no view engine supports the searched locations
Here is the Action Method:
public ActionResult Play(int topicId)
{
var ltopicDownloadLink = _webinarService.FindTopicDownloadLink(topicId);
if (ltopicDownloadLink != null)
{
var path = Server.MapPath("~/App_Data/WebinarRecordings/" + ltopicDownloadLink);
var file = new FileInfo(path);
if (file.Exists)
{
return View("Play", path);
}
}
return RedirectToAction("Index");
}
Here is the Play View:
@model System.String
<div id='player'>This div will be replaced by the JW Player.</div>
<script type='text/javascript' src='/FLV Player/jwplayer.js'></script>
<script type='text/javascript'>
var filepath = @Html.Raw(Json.Encode(Model));
jwplayer('player').setup({
'flashplayer':'/FLV Player/player.swf',
'width': '400',
'height': '300',
'file': filepath
});
</script>
My only hint is that I make some mistake in using the model in the javascript. May you please help me?
Thanks
You are invoking a wrong overload. Here's the correct overload:
return View("Play", (object)path);
or you could also declare the path
variable as object:
object path = Server.MapPath("~/App_Data/WebinarRecordings/" + ltopicDownloadLink);
and then
return View("Play", path);
will also work: