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 ?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With