Dynamic Wizard solution in MVC - asp.net-mvc

I am using MVCSiteMapProvider in a MVC application to implement a wizard based workflow solution. The SiteMap file contains the nodes and branched representing different flows of the wizard.
I have a model class that collects the selected data in the wizard pages (it is one simple class as there is only one item to select from each page). Every time the form gets submitted to the server, I look at what was the recent selection user made and route the model to an appropriate action method and return the associated view.
I am planning to use one common routing controller and an action method where I will submit all my forms(all the wizard page), check from the model property where it has to be routed to and route to that action method using http WebRequest class as seen here and here
MVCSiteMap XML file contains the controller and action method names that I am planning to use for routing along with the model. I dont know how to create the controller object instance and its action using their string names.
Would this approach cause any performance issue. Please help/advise

Related

Mvc access controller antiforgerytoken options

I am using MVC and have a page like contact us. This page has a view and a controller with a action method create. That action method takes in a model and with that model it will add to a database and email users. Is there a way to lock down access to the controller meaning they need to use the view to get access to the controller action method create. I think people can find the model format and just keep hitting the controller. Something like antiforgerytoken but it’s not working in my application because of the classic mode. I get the message This operation requires IIS integrated pipeline mode.

What is the right solution for Menu from database => base view model for layout vs model in httpcontext ()

I am trying to figure out what is the right solution for creating a menu in a ASP.NET. The menu has items and subitems and are subject to user rights. So I have a MenuService that returns the menu for the current user. However I do not know how to implement the menu.
So far I have found 3 possible solutions:
Define a base view model to add on the Layout, and every page view model should derived from this (This would mean that the IMenuService needs to be on every controller)
Use a base controller where I attach the IMenuService and that is going to be attached to the HttpContext.Items before every action (based on this https://dtoncode.wordpress.com/2012/07/30/strongly-typed-models-on-your-layout/)
Define a Controller for menu and in layout call a partial view to place the menu on it.
Which of these solutions are the right one for the job? Are there others?
You could use MvcSiteMapProvider for this - it is very similar to the Web Forms SiteMap provider model, but made for MVC.
Basically, the entire SiteMap hierarchy is loaded into a cache and shared between users. You can configure the nodes in many ways - to load them from a database, you can use one or more dynamic node providers. It has a security trimming feature that automatically reads the [Authorize] attribute on each request and changes visibility of individual items accordingly.
The menu and breadcrumb HTML helpers it uses are templated, so you can change them to output any HTML you need.
Full Disclosure: I made a major contribution to this project.

Umbraco MVC Implementation - View does not depend on Umbraco implementations

I have followed this nice tutorial which explains how you can take even more advantage of using Umbraco as a content delivery system. Tutorial MVC Umbraco => Your model and views should not depend on specific Umbraco implementations which is a huge advantage for real front-end developers.
The controller inherited from Umbraco.Web.Mvc.RenderMvcController in order to access the data from the CMS.
Now my problem is that we can't use #HTML.actionlink for navigation, it seems that this is only supported in SurfaceController.
Now my question is how would we implement navigation inside Umbraco.Web.Mvc.RenderMvcController? Can we still use the native #HTML.actionlink tag?
No you can't. Simply because all requests pass through a single action. In order to retrieve a path to a CMS-managed page, you need to use the node/content traversal the #Model provides. See here for more details on this.
Edit
To clarify, the author of the article is suggesting that the Umbraco implementation should be more in line with a traditional MVC implementation with little or no logic in the views. Therefore, any querying of node data should happen prior to the view (e.g. in the Mappers). So this is where you would have to retrieve the links.
Umbraco's default MVC implementation forces all requests to go via a single action on a single controller. The author's implementation allows the requests to be shared across one controller per document type - which is better IMO. But it still means that things like Html.ActionLink are redundant in the views since there isn't an action per page.
Further edit
If you wanted to build a navigation list with a combination of Umbraco-managed pages and non-Umbraco pages, regardless of the implementation, I would:
Create a child action and view for the navigation in a separate NavigationController that inherits from the SurfaceController
Use the this.CurrentPage property of the inherited SurfaceController to traverse the Umbraco content cache to retrieve the relevant Umbraco-managed pages. You can then use the Url property of each page result to get its path, and the Name property to get the page title
Use this.Url.Action("action", "controller") to retrieve the paths to specific non-Umbraco actions. Alternatively, if the pages are database-managed, use you data layer (e.g. EF, NHibernate, PetaPoco) at this point
Combine these in a Dictionary to make the list you require where the Key is the path and the Value is the page title
Pass this down to the view as the view model.
Of course there any many more things to consider like caching, but in a nutshell, that's a fairly basic implementation.

classic asp page posting to mvc3 controller action

I am currently working with integrating a classic asp site with MVC3. I have some questions on some areas of the integration that I would like some feedback on.
Firstly, I have a asp page posting to an MVC controller action. I have very little scope to modify the asp page. I want to take the form fields posted from the asp page and map them in to a model object. The posted values have obscure names such as "my_name" which I want to map to Name property on the model object. Is the best way of doing this via a Model Binder or is there an alternative?
Next question I have is a follow on from the previous, I am concerned with any cross site scripting so want to check the values of the posted variables to be valid and contain no strange characters etc. Is there something built in to MVC3 that does this out of the box?
When the asp page posts to the controller action, I would like to show a waiting icon while the controller action is processing as the controller action could take 10 seconds plus as it must call external systems etc. Therefore I don't want the post to seem as its hanging. Is it possible to wire up the controller action to return a view with a waiting icon, while the main body of the action is processing in the background and once complete redirects to another page?
Is the best way of doing this via a Model Binder or is there an
alternative?
The best way of doing is a model binder. You can have a custom model binder to take care of the ASP scenario that maps the my_name to Name. Mostly you should have a separate action to handle the requests coming from classic asp and you can link the custom model binder to only this action.
Is there something built in to MVC3 that does this out of the box?
The request validation is enabled as default in MVC. So if an user tries to post a script block to the action MVC will throw exception. Of course you can switch off request validation by decorating the action with ValidateInput(false) if you need.
For long running actions you have to use asynccontrollers.

How do I display multiple pieces of user information on every page in ASP.NET MVC 2?

I'm building a site in ASP.NET MVC 2 that will allow for anonymous users and registered users. When a user is logged in, I want to display multiple pieces of information related to that profile on every page (i.e. hometown, favorite color, etc.). From a view perspective, I understand using Master pages and creating partials to keep it DRY.
However, where I am getting stuck is how do I pass this user information to the view for every page? I already have the relationships between database tables established (I'm using EF), so I can do this on an individual basis for each action through ViewData, but that's obviously ridiculous for every page on the site.
So far, my research has started to lead me down the path of creating a base controller and base view model that the other controllers and view models will inherit from. But I feel like I'm missing something obvious. Any pointers?
If you have your Master page use the RenderAction method, it can invoke controller actions for the various repetitive parts of your page, each of which can perform data access and render a partial view. That allows you to separate your view models while still displaying certain elements on all your pages.
This approach works great for us.
We use a base controller to store it in ViewData.
You could also use an action attribute on the controller rather than inheriting from a base controller.
You could create a base class for your models that contains the data that is display on every page.

Resources