如何在_Layout.cshtml中渲染我的局部视图 [英] How can I render my partial view in the _Layout.cshtml

查看:431
本文介绍了如何在_Layout.cshtml中渲染我的局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC的新手,我在使用控制器渲染局部视图时遇到以下错误。



执行子请求失败。请查看InnerException以获取更多信息。



并在innerException中显示:



T 路径'/'的控制器未找到或未实现IController。



请帮帮我们......





这是我的 DataContract



I am new on MVC, and I am Getting following error while rendering partial view with controller.

Execution of the child request failed. Please examine the InnerException for more information.

and in innerException showing this:

The controller for path '/' was not found or does not implement IController.

Please help me guys......


Here is my DataContract Class

namespace DataContracts
{

    public class StoryWidget
    {
        public string SportName { get; set; }
        public string imageURL { get; set; }
        public string SportTitle { get; set; }
        public string SeriesTitle { get; set; }
        public string AuthorName { get; set; }
    }
}





这是我的控制器



控制器



Here is my Controller

Controller

public class StoryController : Controller
    {
        //
        // GET: /Story/

        [ChildActionOnly]
        public ActionResult _StoryWidgetPartial(string SName)
        {
            var model = new List<StoryWidget>();
            if (model != null)
            {
                StoryWidget item = new StoryWidget() { SportName = SName, SeriesTitle = "IPL 2013", SportTitle = "ICC Hall" };
                model.Add(item);
            };
            return View(model);
        }
    }





这是我的部分视图:



@model DataContracts.StoryWidget







Here is my Partial View :

@model DataContracts.StoryWidget


<div class="nw-img">
                   @*@foreach (var item in Model)
                   {*@
                       <div class="col-6">
                           <a href="#" title="@Model.SportTitle">
                               <img src="images/football_1.jpg" alt="Waqar, Gilchrist indeucted into ICC Hall of Fame"
                                   title="Waqar, Gilchrist indeucted into ICC Hall of Fame" /></a>
                       </div>
                   @*}*@
                   </div>







我在 _Layout.cshtml中调用此部分内容:






And I am Calling this partial from my _Layout.cshtml :

@{Html.RenderAction("_StoryWidgetPartial", "StoryController", "Cricket");}







我在上面的这条线上获得例外

@{Html.RenderAction("





执行子请求失败。请检查InnerException欲了解更多信息。



并在innerException中显示:



没有找到路径'/'的控制器或者没有实现IController。



请帮帮我们......

)

Execution of the child request failed. Please examine the InnerException for more information.

and in innerException showing this:

The controller for path '/' was not found or does not implement IController.

Please help me guys......

推荐答案

我已经修好了自己:



调用
I have fixed my self:

Problem was on calling in
@{Html.RenderAction("

方法。



我刚刚从传递的控制器名称中删除了控制器文本。



Method.

I have just removed controller text from the passing controller name.

@{Html.RenderAction("_StoryWidgetPartial", "Story", new { SName= "Cricket" });}





高于我的代码工作。



above code work for me.


这篇关于如何在_Layout.cshtml中渲染我的局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆