1

I've found myself working on a .Net MVC3 project and sorely missing having Formtastic available in my rails apps.

Are there any good .Net MVC replacements for Formtastic?

mcintyre321
  • 12,996
  • 8
  • 66
  • 103
Joe
  • 86
  • 3

2 Answers2

1

I suggest using MVC3s HTML Helpers.

@model mynspace.MyModel

@Html.EditorForModel()

This html helper generates editor fields for every field in your model, choosing the most likely option. Editing the Editor template, you can change the way it is layed out as well. See this question on changing the template

It can of course be used more customizable by each field with things like:

            @Html.Label("Daily Rate")
            @Html.EditorFor(model => model.DailyRate)
            @Html.ValidationMessageFor(model => model.DailyRate, "Please enter a valid Daily Rate (2 d.p.)")

This can be custom layed out by putting tags around it, i.e. things like <p> or <td>

You can also force an input type using options like:

@Html.TextBoxFor(model => model.DailyRate)
@Html.CheckBoxFor(model => model.DailyRate)
@Html.DropDownBoxFor(model => model.DailyRate, ViewBag.DailyRates)

see here for a full list of options

Community
  • 1
  • 1
IAmGroot
  • 13,760
  • 18
  • 84
  • 154
  • Thanks for the reply - but I was hoping to find something that could wrap up your 3 example lines per-field into a single line of code per-field, like formtastic does. – Joe Feb 13 '12 at 04:24
  • `@Html.EditorForModel()` will generate the entire thing in just one line of code. But doesn't always display as expected. – IAmGroot Feb 13 '12 at 13:51
0

I have a project called FormFactory that lets you do much of the stuff formastic does http://formfactory.apphb.com/

It transforms model objects into PropertyVm objects, which are a viewmodel for an input basically. You could manually create the PropertyVms if you want.

mcintyre321
  • 12,996
  • 8
  • 66
  • 103