1

I have my main index page and I'm trying to render my partial view with the following code:

@{Html.RenderAction("PartialView", "PartialViewController");} 

My Controller for it looks like this:

public ActionResult Index()
{
   GetDataFromProc proc = new GetDataFromProc();
   DataSet ds = proc.CallProcToDataSet("mySproc");
   return PartialView(ds);
}

And my partial view is as follows:

@using System.Data
@model DataSet

<div class="table-responsive">
    <table class="table table-striped">
        <thead>
            <tr>
                <th>Year</th>
                <th>Month</th>
                <th>Hits</th>
            </tr>
        </thead>
        <tbody>
            @foreach (DataRow row in Model.Tables[0].Rows)
            {
                <tr>
                    <td>@row["_year"]</td>
                    <td>@row["_monthName"]</td>
                    <td>@row["_monthCount"]</td>
                </tr>
            }
        </tbody>
    </table>
</div>

Nothing overtly groundbreaking, but each time I run my project I get the following error message: The controller for path '/' was not found or does not implement IController

Clearly I'm doing something wrong, could someone please tell me the standard way for rendering a partial view with an associated controller?

4
  • Have you tried using public IActionResult Index() {? Commented Aug 23, 2017 at 8:55
  • @Will just brings in an error Commented Aug 23, 2017 at 8:56
  • What does the declaration of your controller look like? I.e. Name and what it inherits from? Commented Aug 23, 2017 at 9:06
  • Have you tried commenting partial view rendering line to make sure it is causing the issue ? Are you using mvc area ? Commented Aug 23, 2017 at 9:20

3 Answers 3

2

Your PartialViewController definition can cause this situation. And your action name is "Index" but you are trying to show "PartialView" function. You can try to use it with "Index" named function and without "Controller" addition:

//Usage Style: @{Html.RenderAction("ActionName", "ControllerName");} 
@{Html.RenderAction("Index", "PartialView");} 
Sign up to request clarification or add additional context in comments.

Comments

2

I think you are just missing the correct syntax.

You have your partial view: _MyPartialView.cshtml

In your parent html view (can be another view or layout.cshtml):

@Html.Action("MyPartialView", "MyPartialController")

Create a new controller or use an existing controller:

//
[HttpGet]
public PartialViewResult MyPartialView()
{
    MyPartialViewModel model = new MyPartialViewModel();
    return PartialView("~/Path/To/_myPartialView.cshtml", model);
}

Comments

0

You have multiple issues in your code.

@{Html.RenderAction("PartialView", "PartialViewController");} 

You must define action method and controller method in RenderAction method. So Your PartialView is your method and PartialViewController is your controller.

But in server side you don't implement and you don't have any method called partialView. Instead of that you have Index method. Please change that to PartialView like below.

public ActionResult PartialView()
{
   GetDataFromProc proc = new GetDataFromProc();
   DataSet ds = proc.CallProcToDataSet("mySproc");
   return PartialView(ds);
}

You must name the view as PartialView inorder to match the method name and view name.otherwise you should add your name to return PartialView("PartialView", ds)

And you dont have to give the controller name as "PartialViewController". Omit Controller part and only mention it as PartialView.

@{Html.RenderAction("PartialView", "PartialView");} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.