I will try to describe what I'm aiming for in my project.
Background
I'm building a website in MVC5 using Razor. This website will use the Identity Model for authorization and authentication. I've managed to extract the models and controllers (only those needed for identity management) to a separate class library for easy reuse since I'm planing to use the same logic for several websites.
The Views are still within my web project
Even though I've created my separate class library containing all the models and controllers (the logic basically), I still need to add and maintain all the views (only those for the identity part) within each web application.
This will create problems from a maintenance perspective.
My goal
My goal is to make it easy to maintain, yet flexible to extend/override in certain websites.
So, either I'll create HtmlHelper-classes (extensions?) that output a loginbox for example. That could look something like this:
@Html.MyHelpers.LoginBox()
That would output something like this:
<form method="post" action="MyAction">
<input type="text" name="email" />
<input type="text" name="password" />
<input type="submit" value="Log in" />
</form>
I know I can do this with a string and output to the response, but I would like to make use of the model itself (the UserModel in this case). By doing that I can utilize the functionality for verification of e-mail, display name etc. This approach still require me to add views to my web application, but I don't need to wire up all models to labels etc.
Alternative approach
Another way of doing this might be compiled views. This will not require any views for handling the identity within each web application. However, if I need to tweak the login view for one of those web applications, I could do this by adding a view to the exact same path as the compiled one. I'm not to sure which approach is best.
Now, the questions
I have yet to find a good sample or tutorial out there that covers creating a form in "code behind" and adding other input types, labels, text , AntiForgeryToken etc using a model and then render everything in HTML. Does any of you know such tutorial or sample?
Given the situation, background and goal; which approach do you think is easiest to implement, maintain and override?
Big thanks in advance!
/Fredrik
PS The last question is more of a discussion, so forgive me for asking.
Aucun commentaire:
Enregistrer un commentaire