4
votes

I have a problem with a View. Here's the code snippet:

    public ActionResult AddAdvertisement()
    {
        ...
        return RedirectToAction("AdvCreated");
    }

    [HttpGet]
    public ActionResult AdvCreated()
    {
        return View("AdvCreated", "abc");
    }

then I see the error

The view 'AdvCreated' or its master was not found. The following locations were searched:

~/Views/Advertisement/abc.master

~/Views/Shared/abc.master

If I just go to URL http://localhost/AdvCreated everything is OK. Why ?

3
He's saying if he hits localhost/AddAdvertisement he get's the error.mxmissile

3 Answers

8
votes

What I understand is you are trying to pass a string to View as model. It's not possible. There is an overload of View function like this:

View(string viewName,string masterViewName)

So it looks for a Master View named "abc". If you want to pass a string, convert it to an object.There is an example here.

5
votes

You need to do the following

return View("AdvCreated", (object)"abc");

Or if you are using .NET 4 you can even do this:

return View("AdvCreated", model: "abc");

This forces the Framework to use the correct overloadthat treats the second parameter as the model.

1
votes

Your view/aspx/ascx needs to be located inside one of those folders listed to be used such as the code in your controller.

If you just do this:

return RedirectToAction("AdvCreated");

ASP.NET MVC will assume you have a view/ascx/aspx located in the your controller folder - in your case ~/Views/Advertisement/ folder or the shared folder.

If you have a specific view to display outside the assumed folders, you can specify that directly, such as:

return RedirectToAction("~/MyFolder/AdvCreated.ascx");