References to building dynamic online forms in .NET - asp.net

I would need to create dynamic online forms, e.g. using ASP.NET MVC and Razor as view engine. So you would be able to select a form template, populate it, add new fields, etc.
Are there any references/guides I could follow? I tried searching but couldn't really find any. Creating a main template view with controller, and partial pages with sub-controllers could be one way. This way validation and transformations would be quite well encapsulated.

There is a similar question here on StackOverflow:
Dynamically Produce Razor Views at Runtime?
Also, among the ten tricks for razor views, the two last tips are about building views and eegerly generating code from razor:
http://odetocode.com/blogs/scott/archive/2013/01/09/ten-tricks-for-razor-views.aspx
Maybe those two links can help you getting started at the least

Related

Is it possible to do unit-test ASP.net MVC views without precompiling the views?

I wonder if it's possible to test ASP.net MVC views without pre-compiling the views. I found many example on the internet but none of them could test the view. They could only test the model of the view.
Update
The views are xml template. I have some logic in controller and I want that to get views from the controller.
You can render Razor views standalone using RazorEngine or one of the solutions here. This will give you HTML which you will have to parse.
However, the reason you haven't found any examples of testing views is that few people do it. Views are declarative; they don't have logic. It takes time and effort to develop a test strategy for views. A better strategy might be to move any logic contained in your view into the models where it can be tested easily.

Design tips for a search engine in asp.net/asp.net mvc which vaguely resembles a sharepoint view

Guys i am looking for some awesome tips for developing a page which allows users to search for stuff from the db with the view restricted to only certain columns and the data grouped by and sorted by certain columns..
the source in this case is pretty easy to figure out which is a class which retrieves the search results...kapish..
the view in this case is giving me nightmares as i do not want to write that disgusting piece of code which many asp guys are seemingly used to...overriding row created and data bound of gridview etc etc.... i am thinking of simply rendering a html table itself with the necessary preprocessing applied at the datatable level(group by, sortby etc etc on the in memory object retrieved from the paged results)
i need to know if my thought process so far is right or is there a cleaner way of doing the whole thing in asp.net/asp.net mvc etc etc
Congratulations for not wanting to write "disgusting piece of code"... I spent a few years doing just that and the whole overriding row created / bound / etc. thing is a nightmare.
Your source is a class - great. My preferred method would be to go down the jQuery route, use the jqGrid and write an MVC controller that uses your custom class. Or you could dynamically generate your own HTML table but if you have a lot of data I would save yourself the time and explore jqGrid instead. It doesn't have to be MVC - you could embed it into a standard asp.net website, it's just that the MVC approach makes life easier if you have to expand your application to do more things.

Generic ASP.NET MVC models, controllers and views

I am currently evaluating ASP.NET MVC as a possible technology for a web project. As I am a beginner to ASP.NET MVC I need a bit of advice.
We currently have an ASP.NET system that renders grids from data that is retrieved from a database using OLE DB and data tables. The data is rendered on a web page using a grid view that uses the columns from the database. The system is built in a generic way and driven from the database so that we do not have to write a custom page to display and render each table in the database. We effectively have one ASP.NET page that is used to render and edit different tables in the database.
We are looking at rewriting the system using ASP.NET MVC. Is it possible to have generic models, controllers and viewers in ASP.NET MVC that use dictionaries or lists instead of having separate classes for each table in a database?
On the controller side I have seen the following article to convert a data table to an IEnumerable:
Convert DataTable to IEnumerable
However, I am not sure whether the same can be achieved on the model and viewer side.
Is the whole idea of generic models, controllers and views perhaps contrary to the idea of ASP.NET MVC?
Regards
Lucas
First, you don't need custom models for views or controllers if you know you will be using something generic.
Second, you can write editor/display templates that can work on generic data and you can use them in your views.
We are looking at rewriting the system using ASP.NET MVC. Is it possible to have generic models, controllers and viewers in ASP.NET MVC that use dictionaries or lists instead of having separate classes for each table in a database
Generic solutions are very often a excellent recipe for maintenance nightmare. They work well until you have to extend the application. In my experience you do not switch from the generic solution when you want something extra, but do a small workaround. Next time you'll add another small workaround. And after a year you do not want to touch that application again.
If that's not the case for you, congratulations! You can just use a DataTable as your model in the view.

Divide block of asp.net mvc code into different file parts

I have hundred lines of code asp.net in my view, It make me difficult to find what I need it. So do anyone have some idea to divide it into separate files? As I know, in php , have function include().
Take a look at ASP.NET MVC partial views. These let you break down your view into separate reusable components, similar to user controls in ASP.NET WebForms.

Using User Controls in FormView templates

I find the repetition of sets of controls for each of the EditItemTemplate, InsertItemTemplate, and ItemTemplate templates of a FormView to be tedious and risky, in terms duplicating layout and code etc. I would much rather create a xxxDetails user control, and use this in each template, cutting layout and code location down to one location.
However, this introduces several complexities for data binding scenarios. Are there any extablished patterns or practice guides for using user controls in these scenarios?
Microsoft just added really great support for this in ASP.NET 4.0. It is called DynamicData. They added methods on all data controls called EnableDynamicData(type). There are default templates included in ASP.NET, but you can make your own.
To use built custom templates, just add a DynamicData/Templates directory in your folder. Inside it you can add type views insert and edit templates for all of your data types. The default templates have validators built in so they are a great starting point!
Here is a sample I put together for using custom controls in DynamicData templates. I used a slider for editing integers, and CurrencyInput for money etc...
If you can go with using ASP.NET 4.0 I would highly recommend doing this. Also, even if you can't, you still might want to use the pre-built templates as guidance.

Resources