Asp.net mvc 4 How can I implement multiple forms using a single view?

Asp.net mvc 4 How can I implement multiple forms using a single view?,asp.net-mvc-4,razor-2,Asp.net Mvc 4,Razor 2,I am having a scenario where I need to implement two forms using a single view... There will be a home page having a form each for LogIn and SignUp (similar to Facebook homepage). I created a view for my home page (Index.cshtml) that contains the razor code for both my forms. [@using (Html.BeginForm("LogIn", "Home", FormMethod.Post))] [@using (Html.BeginForm("SignUp", "Home", FormMethod.Post))] However, upon clicking the 'Log In' button for LogIn form or clicking 'Sign Up' button for SignUp f

I am having a scenario where I need to implement two forms using a single view... There will be a home page having a form each for LogIn and SignUp (similar to Facebook homepage). I created a view for my home page (Index.cshtml) that contains the

razor
code for both my forms.

[

@using (Html.BeginForm("LogIn", "Home", FormMethod.Post))
]

[

@using (Html.BeginForm("SignUp", "Home", FormMethod.Post))
]

However, upon clicking the 'Log In' button for LogIn form or clicking 'Sign Up' button for SignUp form, the runtime throws an error basically saying that I still need to create views for both LogIn and SignUp actions, even though I have already implemented the HTML forms in my index.cshtml

[NOTE: I am not using ASP.NET membership provider. And this question is generally for two forms, can be any two forms.]

So my question is: Do I really need to create two more views named LogIn.cshtml and SignUp.cshtml? Won't this cause code duplication? I'm quite new to MVC 4 and I hope you understand what I'm trying to do here, so all I want to know is whether there is any other way to implement this? (jQuery, AJAX or something)

public class HomeController : Controller
{
    [HttpGet]
    public ActionResult Index()
    {
        return View();
    }

    [HttpGet]
    public ActionResult LogIn()
    {       
        return View();
    }

    [HttpPost]
    public ActionResult LogIn(Account acc)
    {                  
        // some code
        return View();
    } 

    [HttpGet]
    public ActionResult SignUp()
    {       
        return View();
    }

    [HttpPost]
    public ActionResult SignUp(Account acc)
    {                  
        // some code
        return View();
    }       

}

#1

You could specify the view you want to be returned:

[HttpGet]
public ActionResult SignUp()
{       
    return View("LogIn");
}

#2

That is because each controller method expects to have a corresponding view. Unless you specifically tells it what view to use, for example return View("use_this_view") or return View("path_to_the_view/use_this_view.cshtml").

#3

Thank you very much... return View("use_this_view") worked perfectly.