A public action method Index.cshtml was not found on controller
Hi all , how to solve error public action method Index no found in controller
I have added mvc view in to partials folder and then create a macro and call html action. I have link to the page and in page content I have added partial view macro file call Html.ActionI to index method on listSites Controller
for all options page return error...
tried adding [ChildActionOnly] then [HttpPost] then [HttpGet]
System.Web.HttpException: A public action method '~/Views/Partials/ListSites/Index.cshtml' was not found on controller 'myicCodeProject.Controllers.ListSitesController'.
Your SurfaceController looks good, I suppose you could post your razor code, but I'm wondering if you have a similar situation that catches me out sometimes, which is that my browser has cached that route as a 404 and won't change its mind until I kill all caches + I also feel more comfortable knowing that IIS (or IIS Express) has definitely restarted and added the route to its route table.
Barring that, you have my sympathy. And I leave you to someone else with an eagle eye.
if i enter @{Html.Action("ListSites", new { controller = "ListSitesController"});} i get route error No route in the route table matches the supplied values
if enter - page is blank
@{Html.Partial("~/Views/Partials/ListSites.cshtml", new SiteModel());}
Let first start with the syntax. A code block @{ ... } means running code, while @stuff means print out stuff.
If you want to wrap Html.Action in a code block @{ ... }, you need to use @{Html.RenderAction(...)}, otherwise nothing will be printed out on your screen.
To keep it simple, I always use @Html.Action(...) and @Html.Partial(...)
I suggest you do the same. Except if you have a good reason not to of course.
If you need to choose between View and PartialView, the PartialView is a good solution if you return partials (that is also childActions)
Speaking of [ChildActionOnly]. If you are ONLY allowed to call a method on a controller from @Html.Action(), then you could add this attribute. It's not obligated though. It is only to prevent you are calling the method from the browser directly.
To answer your questions: if the route is not found, it feels to me that the code is not compiled.
And why macro is not printing the code: I guess that has to do with the codeblock vs @stuff thing.
A public action method Index.cshtml was not found on controller
Hi all , how to solve error public action method Index no found in controller
I have added mvc view in to partials folder and then create a macro and call html action. I have link to the page and in page content I have added partial view macro file call Html.ActionI to index method on listSites Controller
for all options page return error...
tried adding [ChildActionOnly] then [HttpPost] then [HttpGet]
System.Web.HttpException: A public action method '~/Views/Partials/ListSites/Index.cshtml' was not found on controller 'myicCodeProject.Controllers.ListSitesController'.
Hi pat,
Could you post the code of myicCodeProject.Controllers.ListSitesController
But my money is on that you have made the class private, it needs to be public.
Cheers
Jonathan
Hi Pat,
Well I lost my money there.
Your SurfaceController looks good, I suppose you could post your razor code, but I'm wondering if you have a similar situation that catches me out sometimes, which is that my browser has cached that route as a 404 and won't change its mind until I kill all caches + I also feel more comfortable knowing that IIS (or IIS Express) has definitely restarted and added the route to its route table.
Barring that, you have my sympathy. And I leave you to someone else with an eagle eye.
Cheers
Yes you loose the money :)
Thanks any way i'll try clear caches and see
Pat
How are you calling the @Html.Action(...)? Which parameters do you add?
I have tried
then
I am calling this from Macro and using insert macro option in RTE ( not from template - if i do so its works fine list my sites)
I have changed the method to Controllers name public class ListSites() and return PartialView
now I don't get error about public method but still page is blank
then I changed
@{Html.Action("ListSites", "ListSites");}
no error but blank page :(Hi,
Html Action can't call a partial. It can only call an
Action
on a controller. E.g:If you want to call a partial (without a controller) then just call
Sorry i am confused now.
if i enter
@{Html.Action("ListSites", new { controller = "ListSitesController"});}
i get route error No route in the route table matches the supplied valuesif enter - page is blank @{Html.Partial("~/Views/Partials/ListSites.cshtml", new SiteModel());}
Please do help me to sort out :)
Hi Damiaan,
do you remond controller to return View () or Partialview ?
I really need to figure out, why if I call html.action in Template that load my sites and not in macro ?
What do i do wrong here ? i f I call in macro do i need to add [ChildActionOnly] what do i miss here ?
Ok. You are mixing a few things here.
Let first start with the syntax. A code block
@{ ... }
means running code, while@stuff
means print out stuff. If you want to wrapHtml.Action
in a code block@{ ... }
, you need to use@{Html.RenderAction(...)}
, otherwise nothing will be printed out on your screen.To keep it simple, I always use
@Html.Action(...)
and@Html.Partial(...)
I suggest you do the same. Except if you have a good reason not to of course.If you need to choose between View and PartialView, the
PartialView
is a good solution if you return partials (that is also childActions)Speaking of
[ChildActionOnly]
. If you are ONLY allowed to call a method on a controller from@Html.Action()
, then you could add this attribute. It's not obligated though. It is only to prevent you are calling the method from the browser directly.To answer your questions: if the route is not found, it feels to me that the code is not compiled. And why macro is not printing the code: I guess that has to do with the codeblock vs @stuff thing.
I hope this helps
Kind regards
Spot on ... thank you very much. You save me
I have changed Partial View macro call to Html.Action and remove {}
all works fine. I owe you a coffee / tea and a chocolate , actually more than that.
Thanks again for summarising each option above.....
Glad it works!
Find me on codegarden and let's have a coffee together! ;-)
Kind regards
Damiaan
is working on a reply...