0

我正在使用C# 和 Razor开发MVC3应用程序。当我需要显示一个播放视图时,我遇到了问题。

Play 操作方法用于检索FLV (Flash)文件的路径,然后将其传递给Play View以重现该文件。当我使用应用程序正确return View("Play")呈现视图时。但是,我需要将路径变量传递给视图,如代码所示。当我这样做时,我收到以下消息:

未找到“播放”视图或其主视图,或没有视图引擎支持搜索到的位置

这是操作方法

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");
}

这是播放视图

@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>

我唯一的提示是我在 javascript 中使用模型时犯了一些错误。你能帮帮我吗?

谢谢

4

4 回答 4

2

您正在调用错误的重载。这是正确的重载

return View("Play", (object)path);

或者您也可以将path变量声明为对象:

object path = Server.MapPath("~/App_Data/WebinarRecordings/" + ltopicDownloadLink);

接着

return View("Play", path);

也将起作用:

于 2011-06-09T11:23:07.323 回答
1

View is overloaded in a way that if you pass a string (with static type string) into it, it will land in the wrong overload

You want this overload:

View(String, Object)    Creates a ViewResult object by using the view name and model that renders a view to the response.

And that's the overload you actually called:

View(String, String)        Creates a ViewResult object using the view name and master-page name that renders a view to the response.

So it thought that your model is the name of the master-page. The workaround is making the static type of the model you pass in something other than string:

View("viewname",(object)model)

No idea why the developers thought that overloading View in such an ambiguous way is a good idea...

于 2011-06-09T12:05:53.123 回答
1

您应该将模型转换为对象return View("Play", (object)path);,否则将调用第二个参数是母版页路径的方法

于 2011-06-09T11:22:48.560 回答
0

在我看来,您需要在控制器中执行索引操作。

该错误与缺少索引操作有关,而不是与播放视图有关。尝试实施索引操作,看看会发生什么。

于 2011-06-09T11:23:30.303 回答