Reputation: 1790
What is considered best practice for the following example:
Are these 3 separate views? Or the same view with multiple route options?
ActionResult ChangePassword()
ActionResult ChangePassword(string token)
{
// if bad token show this error view partial? set viewdata item and let cshtml decide what to show?
}
Or is a situation like this not really all that logical?
Upvotes: 1
Views: 159
Reputation: 45303
I would separate it into 2 pages:
Change Password
Reset Password
These two pages seem to operate differently enough that I think you would be better off using separate views, actions, & view models. If you get to the end though, there is nothing wrong with refactoring to remove duplication, but I would predict they will not be as similar as you anticipate.
Upvotes: 3
Reputation: 16743
I think you could get away with a single View, you just need to build a robust enough ViewModel:
public class ChangePasswordViewModel(){
public string OldPasswordHash {get; set;} //Remember never to store password in clear text
public string NewPassword{ get; set; }
public string RecoveryToken { get; set; }
}
Based on these properties, you should have all you need to flesh out the presentation logic in your View to cover off all the use cases you describe above. Let me know if you need further guidance.
Upvotes: 2
Reputation: 12196
I think the best validation for ASP.NET MVC
will be Validation Attributes
on the properties you will like to validate.
Upvotes: 1