asp.net mvc - Action does not find View or its master -


i have following action:

public class articlescontroller : controller {      public actionresult article01()     {         return view();     } } 

which returns view , seems work fine.

now try add actionname:

    [actionname("bla-bla-article-1")]     public actionresult article01()     {         return view();     } 

now calling: /article/article01 returns

'the resource cannot found.'

now try this:

[actionname("bla-bla-article-1")] public actionresult article01() {     return view("~/content/views/articles/article01.cshtml"); } 

and here get:

the view '~/content/views/articles/article01.cshtml' or master not found or no view engine supports searched locations. following locations searched: ~/content/views/articles/articles01.cshtml

you have realize default, method name action name. but, once you're overriding convention using [actionname] attribute, url through access action subject change well.

in case be:

/articles/bla-bla-article-1

and, when you're using return view() without specifying view name, it's being determined automatically current route parameters, , after attribute applied, value bla-bla-article-1.

that's why have specify explicitly:

return view("article01"); 

see msdn


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -