0

very simple basic question I have only route:

 routes.MapRoute(
                "Widget", // Route name
                "Widget/Frame/{postUrl}", // URL with parameters
                new { controller = "Widget", action = "Index", postUrl = UrlParameter.Optional } // Parameter defaults
            );

And when i try to open following url:"http://localhost:50250/Widget/Frame/qwerty"

I have an error:

The view 'qwerty' or its master was not found or no view engine supports the searched locations. The following locations were searched:

Well...why?

Controller code:

public class WidgetController : Controller
    {
        //
        // GET: /Widget/

        public ActionResult Index(string postUrl, int? blogEngineType)
        {
            return View(postUrl);
        }




    }
3
  • Show us the controller Widget's action Frame's code. Commented Mar 12, 2012 at 22:30
  • but i havent Frame action only index. anyway see update. Commented Mar 12, 2012 at 22:32
  • See this:- stackoverflow.com/questions/6118840/mvc3-and-rewrites/… Commented Mar 15, 2012 at 4:51

4 Answers 4

3

You are returning a View with

return View(postUrl);

Since there is no name of the view (in this overload), the method uses the Action name as view name and looks for it. You probably meant to do

return Redirect(postURL);
Sign up to request clarification or add additional context in comments.

1 Comment

Oh yees! Thanks! I actually mean return View((object)postUrl);
2

I would hazard a guess and say it's because it's actually trying to use the action name of Index(), since that's the default action that you've specified. You're not passing an {action} parameter through the url, so where else will it get the action from?

Can you change your url pattern to Widget/{action}/{postUrl} and see if it works then?

Either that, or set the default value of action to Frame instead. Basically, it has no way of knowing that you're looking for the Frame action, so it fails.

Edit: I see what you're doing now - the action's name is actually Index, right? In that case, I'm not sure, we need to see your controller code. I'll leave the above answer in case it's useful.

Edit 2: You're passing the value "qwerty" as the view name - do you have a view named "qwerty" in the views folder?

If you intend for it to be the model, and for the view name to be "Index", you should call return View((object)postUrl); instead, so that it doesn't get confused.

2 Comments

Widget/{action}/{postUrl} this doesnt work too with url:"localhost:50250/Widget/index/qwerty"
See my edit. The route isn't your problem, it's the view name.
2

It's because your return statement is return View(postUrl); and when you pass a string to the View() method it is interpreted as the name of the view to use. So it looks for a view called qwerty since that's what's in that variable. If you want to hand postUrl as a model to the view of your Index action, you'll have to change your return to be return View("Index", postUrl)

1 Comment

Or like Steve says, use View((object)postUrl) so it's forced to treat it as an object.
1

Are you sure there is a View called 'qwerty' in the Shared or Widget folder within the Views parent folder? Otherwise you probably want to use return RedirectToAction(postURL);

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.