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?
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.
精彩评论