asp.net mvc custom template for application forms and page - asp.net-mvc

everyone, I'm really new with asp.net mvc
I have given this new task that converting existing application using asp.net webform into asp.net mvc
This application have basically have 3 type template form:
Grid Template (include the navigation such paging and search, and input/view form/panel shown after click, can be below or hide the grid)
Process Template (Grid with check box on each item to process)
Non-Grid Template (just input form, usually used for application parameter form)
This application also has some template pages, but basically this template page is combining just 1 template form or more (can be same template form), e.g parameter application form or sales order application (master and detail). The page can also has many detail show in tabs.
How do I achieve this templates using asp.net mvc as efficient as possible rather than just create new form and copy-paste from the other form.
I mean to minimalize the same code I have to write rather the specific thing that differentiate the form purpose, e.g the code just show the input form after click item.
Can anyone show me how I can do it or solution that came near to what I need?
Any link to tutorial, step by step, or anything?
Or if there any reasons I can't/shouldn't do it with asp.net mvc and what is the best way?
Thanks in advance and sorry if there are any mistakes in my words.

Editor/Display templates
They are mostly used for edit/display forms such as editing/displaying user profile data form, etc. Kind of like your Non-Grid Template. You can create Object templates, place them in the corresponding folders of the solution and they will be automatically every time you render your model via Html.EditorForModel() or Html.DisplayForModel helpers. Here is a good article to start with ASP.NET MVC 2 Templates, Part 4: Custom Object Templates
Shared views
I'm not sure what your Process template looks like but it seems it's a fixed number column grid like a one column with chackboxes and one more column with names of the items to process. In this case you'd better create an interface and a shared view. Then you can use the interface to map your view model to and render it with your shared view via Html.Partial helper.
Html helpers
For more advance grid templates just use a grid template, there are a lot of online, personelly I prefer Grid helper from MvcContrib library.
Two combine different templates within a single page use layout, sections and again shared view. Here is a good video about how to create and use them Asp Net MVC 4 - 02 Creating Layout, Views and Partial Views
Can't advice anything more specific as I don't really know what you WebForm application actually looks like but I think I described everything you need to start with.
Hope it helps!

Related

User Control Equivalent in ASP.NET MVC 4

I'm working on a new ASP.NET MVC 4 app. I'm really trying to do things the "MVC" way. In particular, I'm interested in using the Razor view engine. Please note that I come from a web forms background, so my questions may seem awkward.
I'm trying to learn if there is something equivalent to user controls in MVC? If so, what are they called? If not, what is the recommended way to creating a reusable component in MVC?
You're looking for #Html.Action and #Html.Partial.
They allow you to either render a partial view or a full blown controller action in a view. This is a common pattern of reuse in MVC land.
Occasionally you would want to make displayFor or editorFor templates, if a controller action is too heavy. The rule of thumb is if you need to do it multiple times on the page and it needs to be posted back in a form, think about doing it in a template.
Controls in asp.net cover a rather large swath which MVC granularizes a bit more.
To creating a reusable HTML component in MVC you can create a partial view in the Views/Shared folder and use #HTML.Partial("_PartialViewName") to include it in any other view or partial view. You can find out more about partial views in this article.
You could try:
Add a View Start _ViewStart.cshtml in Shared folder
Make Layout Null (if required) #{ Layout = null; }
Call this page where you want like #Html.Partial("_ViewStart")

ASP.NET MVC Custom Controls

Is it safe to say that custom controls with ASP.NET MVC are most times just partial views? And if that's the case, I'm guessing it's always up to the implementing application to dictate the behavior (through controller code) of these controls?
I have done a bit of searching, and there is almost no resources on ASP.NET MVC custom controls (either that, or I'm missing the mark with my Google skills).
Partial views are more a template for either a control or a set of controls that can be shared between views.
I'm not sure they are "Custom Controls" as such and it sounds like you are coming from an ASP viewpoint.
I think you need to first get in the mindset of MVC and out of ASP.
So for a list of items you may have a partial view that takes the list of items and a partial view that takes an actual item. So "pvCustomerList<List<customer>>" and "pvCustomer<customer>".
The pcCustomerList iterates through the list and creates a pvCustomer for each customer in the list.
Partial Views don't really have code in the controller. Instead they are passed data from the view. If there is a submit action in the partial view, then this is either handled by the controller for the view or a jQuery post back.
I hope this clears things up a little for you.
Have you checked out NerdDinner sample?
There is nice article on asp.net mvc website regarding form helpers (helper methods for views). there is explained how to create custom helper method
Link is http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs

How do I generate content once and reuse it across all pages in ASP.NET MVC?

In my ASP.NET MVC site all pages share the same content (header & top menu).
What are my options to generate that content is only one place and reuse it in all pages. I also want the link the user is currently on to be handled appropriately (not show up as a link).
In MVC3 this is usually done in the layout page: http://weblogs.asp.net/scottgu/archive/2010/10/22/asp-net-mvc-3-layouts.aspx
In my ASP.NET MVC 2 application, I use a Master Page as suggested by Rich. I just wanted to add that I use a Master Model that all of my view models inherit from to return dynamic data that is needed in the master page (i.e. something to help you determine the active link to highlight). Every time I render a view I explicitly pass it a view model so those values from the master model are always available.
That master model gets its data from things that are globally available (i.e. my custom identity, http context properties, etc.) - because I don't want to manually initialize those properties every time I render a view (which defeats my goal of thin controllers).
You can also use ASP.NET Master pages. http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx
If you start a new ASP MVC project in Visual Studio I believe it'll give you a masterpage in /Views/Shared
If it's dynamic data; then you can always use a RenderAction() inside of a Masterpage. Is this dynamically generated data?

Struts2 dynamic form elements

I would like to create little higer-level framework on top of Struts2 which can take form element description from Action and render a complete form, in order to avoid having a separate JSP files with hardcoded form elements for every form in a large web application (so if I manage to do this I will have just a few generic JSPs for data form and few for layout). Application is extremely data-driven.
My idea is to create form description using custom objects in the Action (i.e. Button, TextInput etc.) and then to create a single JSP page that will render eveything out.
What is the best way of doing this? Can you propose some concrete way to do this?
I don't want to write something if I can reuse the existing code with some effort.
Any ideas are appreciated.
Kind regards,
Bozo
It seems to me you are trying to build a web framework on top of another, I doubt Struts2 is appropiate for that.
If you have a data-driven web app for which you dont want to write many similar JSP (or whatever view lang) pages, perhaps you'd better look at some frameworks with scaffolding abilities , eg Grails http://www.grails.org/Scaffolding
I did what I asked in the question myself - I have created a few generic JSP templates (list, edit etc.) which take application parameters and create output grids and forms using the struts2 and simple HTML tags. Using this method generic tiles definitions can also be created and used. So at the end using simple definition in the struts2 action, the grid and form is generated.

Large data entry pages using ASP.NET MVC

I am working on a large data entry page using the default ASP.NET MVC theme. Due to the large number of controls on the page it would be good to use a two column fieldset so the user does not need to scroll. I can't see any templates in the MVC design gallery that use a two column data entry page, they are all geared towards standard website designs. Has anyone seen any? It would be great to have templates for different data entry scenarios.
Thanks
Danny
What you can do is create your own T4 (Text Template Transformation Toolkit) file. You can find out more here. This will give you an extra view content option in your "Add View" dialog box, generating the HTML however you've specified.
If your problem is to show all controls on single window without scrolling and may be using two columns,Right!
I have another solution for you.
And that is Wizard. check out this link and this link.
Your form will look nice!
If your issue is layout, you can lay it out in the design view first (or dreamweaver or the designer of your choice) then add the MVC specific code.

Resources