I want to create a view that can be used twice on the same page, each time with a unique id.
At the moment I'm using two approaches to do this kind of thing
Editor Templates
stevensanderson's approach for having controls created on the fly
Editor Templates are the easiest as they take of the name mangling (e.g. parent1_parent2_childId) but Editor Templates can't be used across Areas and I really like Areas
Is there a 3rd option?
thanks
You can pass a model to a child view in the RenderPartial extension method. Use this mode to pass a desired id, or something from which it can be obtained.
Related
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!
I'm passing a list of controls into the view (e.g. information such as - the Id of the control, the type of control, whether it's a required field etc) and am then going to build them up either via the view or through jQuery...but i was wondering whether it would be vastly more efficient if the html controls were build up from jQuery?
Cheers.
but i was wondering whether it would be vastly more efficient if the
html controls were build up from jQuery?
No, it would be vastly more efficient to use an ASP.NET MVC view and have those controls built on the server using the view model that is passed from the controller to the view.
If you want to dynamically add/remove controls later on the client then yeah, jQuery would be a great choice.
Can anyone please tell what's the exact differences between partial views and user controls in an MVC app?
Which one is feasible to use? I am using user controls for filling my views which have one or more tabs(which i have added using Ajax control toolkit).
I want to know about advantages/disadvantages while using partial views and user controls.
Thanks,
Kaps
I mostly agree with Ryan. However one point to consider though is that user controls have an implementation of events whereas partial views do not.
Kindness,
Dan
Partial Views and User Controls are basically the same thing. User Controls are just a way of distinguishing between regular Views and Partials. When you see the "Partial.ascx", it's immediately obvious that it's a Partial because the icon is different in Visual Studio.
There's nothing stopping you from using a regular *.aspx file as a Partial. In fact, some people do exactly this, and prefix their aspx Partial names with an underscore (ex: _UserStatus.aspx).
My personal preference is to use the ascx files instead because it's easier to tell that something is a partial at a glance.
Is there a new model or best-practise for creating complex controls in asp.net MVC?
Do you use code-behind or inline to mirror your view pages?
My model is this:
I tend to use Partial Views when there is a view element that I'll need to use more than once. Or if I need to display multiple complex object in a view.
I use RenderAction from the futures assembly when I need a "reusable widget" of sorts. It has it's own controller and is better at handling more complex logic than a Partial View.
Finally, I tend to write Html Helper methods for things I may use in other projects (like paging links, etc).
I would use a partial view for complex things. Check out this article
Controls in MVC don't generally have (any) code behind. You use PartialViews as ascx controls, you pass them a model and you display the contents of the model.
You can create custom controls in mvc and these compile to a dll which is moveable between projects etc and these are a little more complex but essentially they spit out html like the partial view does.
You can also create jQuery plugins that are pretty cool and again, they can spit out html based on a model.
So a typical mvc view may be comprised of several partial views each of which are dedicated to a model or hierarchy of models.
Partial views can also display partial views so you can send a complex model to a partial view which in turn renders other partial views each of which deal with a more atomic part of your model.
I've been writing a lot of my own HtmlHelper extension functions. The November meeting of http://www.c4mvc.net/ that was recorded today gives some great examples of control type code placed in HtmlHelper extension functions. The recording should be online soon.
You may also want to check out the Telerik Extensions for ASP.NET MVC. They're open source, so even if you don't use their controls, you can get some insight into controls in ASP.NET MVC by taking a look at how a commercial control vendor approached the problem.
Coming from a PHP turned webforms turned ASP.NET MVC background, I find myself relying a lot more on basic html/css/javascript.
I've never been a fan of controls, even with webforms because they always ended up being messy compared to js/html/css counterparts.
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.