I know similar question already asked, but my question related to saving state of the page. I use same model for simplicity. Assume I have following model:
public class LoginRegisterViewModel
{
public string LoginUsername { get; set; }
public string LoginPassword { get; set; }
public string RegisterUsername { get; set; }
public string RegisterPassword { get; set; }
public string RegisterFirstName { get; set; }
public string RegisterLastName { get; set; }
}
I am interested in 2 things:
1- I must know wich button has been clicked
2- I must preserve both form data. It means when user already filled LoginUsername for Login and then decide to register for sites and clicked Register button, in response both form state will be saved.
Using following approach:
@model LoginRegisterViewModel
@using (Html.BeginForm("Login", "MemeberController", FormMethod.Post, new {})) {
@Html.LabelFor(m => m.LoginUsername)
@Html.TextBoxFor(m => m.LoginUsername)
@Html.LabelFor(m => m.LoginPassword)
@Html.TextBoxFor(m => m.LoginPassword)
<input type='Submit' value='Login' />
}
@using (Html.BeginForm("Register", "MemeberController", FormMethod.Post, new {})) {
@Html.LabelFor(m => m.RegisterFirstName)
@Html.TextBoxFor(m => m.RegisterFirstName)
@Html.LabelFor(m => m.RegisterLastName)
@Html.TextBoxFor(m => m.RegisterLastName)
@Html.LabelFor(m => m.RegisterUsername)
@Html.TextBoxFor(m => m.RegisterUsername)
@Html.LabelFor(m => m.RegisterPassword)
@Html.TextBoxFor(m => m.RegisterPassword)
<input type='Submit' value='Register' />
}
I will know which button has been clicked. But I don't know what information other forms have. If I just use single form, I don't know which button has been submitted the form (I know I can user Request.Form["buttonvalue"], but I think it is not clean solution).
In the worst case it is possible that the model contains information about one grid:
public class LoginRegisterViewModel
{
public string LoginUsername { get; set; }
public string LoginPassword { get; set; }
public string RegisterUsername { get; set; }
public string RegisterPassword { get; set; }
public string RegisterFirstName { get; set; }
public string RegisterLastName { get; set; }
public List<RowModel> Rows {get; set;}
}
When I just send login form, I don't know current page, sorting, filters in my page. How MVC will help these problems?
Update 1:
I did not want to use JavaScript and jquery for some reasons.