I have a view name EmployeeForm.cshtml and inside EmployeeController I have two action method MyView() and RandomView(). MyView() returns object of Employee Model while RandomView() method returns the object of EmployeeViewModel.
But the URl request goes as like: http://localhost:port/Employee/EmployeeForm i.e. MVC expects an EmployeeForm() method inside EmployeeController.
How can i correct this error ?
No it's not.
You view form should point to the name desired, whatever it's the current MyView() or another custom name by decorating the controller action with attribute.
No matter what you choose, the view form must match the action name(or attribute name).
[ActionName("EmployeeForm")]
public ActionResult MyView()
{
// You code here
return View(); // Will use MyView page
return View("SomeViewName"); // Will use SomeViewName page
}
Concerning View page, this is almost not related. You can set the controller action to return whatever View page you want using View("SomeViewName", myModel)
.
Note: When using BeginForm without passing the desired action, it will use the current View file page as the target form Url action name.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments