user3329046
user3329046

Reputation: 41

how do i change mvc views from the controller?

i have the razor view add_event.cshtml:

 @model InputEvent

 @using (Html.BeginForm("Save", "MyEvent"))
 {
     inputs
     ...
     ...
     ...
     <input type="submit" value="Save" />
 }

with the post controller here:

 [HttpPost]
 public ActionResult Save(InputEvent y)
 {

     ...
     ...
     ...
     return View()
}

I want to return to a specific URL with return View(). I have tried putting the string in for the url: return View("App/page"). but the url that i am taken to every time is "/MyEvent/Save". This URL doesnt even exist.

How do get to the view of a specific url?

EDIT: thanks. i had tried that before but i switched the two strings up

Upvotes: 0

Views: 34

Answers (2)

Kartikeya Khosla
Kartikeya Khosla

Reputation: 18873

Use RedirectToAction()

return RedirectToAction("ActionName","ControllerName");//OR return RedirectToAction("ActionName","ControllerName", routevalue);

Docs

Upvotes: 0

4rchie
4rchie

Reputation: 1234

You could try redirect if this is an option for you.

return RedirectToAction("SomeView", "Home");

Also passing a model should do. I have

return View("SomeView", someViewModel);

in my code and it works just fine.

Upvotes: 1

Related Questions