Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it considered bad practice to split a single form among multiple partial views?

Tags:

c#

asp.net-mvc

I am currently working on an ASP.NET MVC 3 app where I have a particular view that is setup like a wizard (using a jQuery plugin). Each of the wizard steps is part of a single form, where each "step" is split in to its own <div> element. I decided to create partial views for the contents of each "step". I did this for a few reasons. One being that it keeps the code for each step neat and organized. The other being that it allows me to more easily/neatly include or exclude steps from the wizard on the server side.

Right now, my "main" view looks something like the following:

@using (Html.BeginForm)
{
    <div class="step" id="step1">
        @Html.Partial("Step1")
    </div>

    <div class="step" id="step2">
        @Html.Partial("Step2")
    </div>
}

I am wondering if doing something like this would be considered bad practice and if I should just consolidate the code for all "steps" in to a single view?

like image 560
Justin Holzer Avatar asked Nov 04 '22 18:11

Justin Holzer


1 Answers

No, nothing inherently wrong with that approach.

There's a small performance overhead, but likely to be of no consequence.

If it makes it easier for you to develop and maintain, feel free.

Edit: If you're worried about mapping sub-models, as we referred to in the comments, consider using ViewData.ModelMetadata.PropertyName in the partial view to derive the ID's of the input controls.

like image 182
Steve Morgan Avatar answered Nov 15 '22 04:11

Steve Morgan