0

We have an MVC 4 project in which we have to create about 100 forms. Now the developpers are going to start creating the forms , should we create the forms as views or partial views.. ?

Would writing the forms in partial views create any issues for us later when tying up with view models.. ?

tereško
  • 58,060
  • 25
  • 98
  • 150
Prakash
  • 471
  • 1
  • 8
  • 19
  • You should use partial views when you have to use them multiple times. Partial views can be reused in other views. But if you just need the form once, don't create partial views. – Florian Mar 21 '14 at 09:04

4 Answers4

1

Partial views are useful for views modularization and are the best way of dealing with repeatable view parts. Regarding the forms, I would propose to call @Html.BeginForm(...) in in your view, while separating form content in partial view or Custom Editor Template.

Also read more about trend called Atomic Design. It provides nice philosophy and terminology about partitioning views into logic components. It can be also applied to ASP.NET Razor capabilities.

Bartosz Sypytkowski
  • 7,463
  • 19
  • 36
0

A view is a complete web page with html headers. A partial view is only body html code and you can reuse it whenever you need.Partial views help us to reduce code duplication. Hence partial views are reusable views like as Header and Footer views. If you want to use your forms in more than one place then you can use partial view. if you use it only once then go with view..

Rashad Valliyengal
  • 3,132
  • 1
  • 25
  • 39
0

Well, writing the forms in partial views creates no issues at all. Instead it facilitates you to develop with ease. If you have used any Scaffolding Library, you must have seen they do implement this practice very often.

A very simple example:

For Creating a record and Editing a record, both will have the same controls on the form - just with few ReadOnly of them. So, here, creating a partial form "_CreateOrEdit" will save your time and efforts.

Just make sure that you exclude tags, I mean @Html.BeginForm() or whatever helper class you're using to generate form tags, in view, not in partial. Keep only the common controls in both.

Hope I'm making sense, thanks!

Sunny Sharma
  • 4,688
  • 5
  • 35
  • 73
0

well it is not required to make your all views as partial views because main use of Partial view is usability when you want to use particular view manytimes then go for Partial views or you want to do ajax call then its better to use partial views.

Anything you would use more than once. For instance on this page for SO, you see the listing of related posts over to the right. That is on multiple page, so why create it multiple times. You can pass data to the partial view to customize it based on certain criteria.

I do not like it for certain things like login, where I would rather take the user to a login page. However that scenario is used often.

Neel
  • 11,625
  • 3
  • 43
  • 61