开发者

Partial view displaying error

I created a drop down list in a partial view and I am trying to render that on my aspx page. I am getting an error:

{"Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'."}

This is my aspx page where I am using the ascx control:

<td>
    <% Html.RenderAction("getFilterdData");%>
</td>

My ascx control looks like this:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<assist>>" %>
<%=Html.DropDownList("Assists", (SelectList)ViewData["Assists"], "--Select One--")%>

and my controller code is like this:

public ActionResult getFilterdData()
{
    scorerep sc = new scorerep();
    ViewData["Assists"] = new SelectList(sc.FilterData(), "assist_a","");
    return View();
}

Why am I getting this开发者_运维技巧 error and how can I fix it?


It is difficult to help without seeing the entire exception stacktrace. Here are a few tips:

  • Make sure that your partial Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<assist>>" and not Inherits="System.Web.Mvc.ViewPage<IEnumerable<assist>>". You are using an ASCX partial and inheriting from System.Web.Mvc.ViewPage which is wrong.
  • Make sure that your partial view is called exactly the same as the controller action: getFilterdData.ascx (I see a typo here)
  • Make sure that the Assist class contains a property called assist_a as that's what you are using when rendering the dropdown
  • Make sure there is no exception being thrown inside the getFilterdData controller action while you are fetching the data.

Here's a working example:

Model:

public class Assist
{
    public string Id { get; set; }
    public string Value { get; set; }
}

Controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult GetFilteredData()
    {
        // TODO: replace with your repository logic
        ViewData["Assists"] = new SelectList(new[] {
            new Assist { Id = "1", Value = "Assist 1" },
            new Assist { Id = "2", Value = "Assist 2" },
            new Assist { Id = "3", Value = "Assist 3" },
        }, "Id", "Value");
        return View();
    }
}

View (~/Views/Home/Index.aspx):

<% Html.RenderAction("GetFilteredData"); %>

Partial: (~/Views/Home/GetFilteredData.ascx):

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Assist>>" %>
<%= Html.DropDownList("Assists", (SelectList)ViewData["Assists"], "--Select One--") %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜