Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.
Email<input type="text" id="email" /><br />
Re-enter Email<input type="text" id="confirm-email" />

I'm thinking that I want a model so that I can have this partial page strongly typed. But what a lame model....

It would look like this, and if this is a good Idea, what should I name this model?

public class ConfirmEmailModel?????
{
    [Required]
    [Display(Name = "Email",ResourceType=typeof(mvc3test.Resources.Common))]
    public string Email{ get; set; }

    [Display(Name = "Confirm Email")]
    [Compare("Email", ErrorMessage = "no match.")]
    public string ConfirmEmail{ get; set; }
}
share|improve this question
add comment

4 Answers

call it a "view model" as its not really a model, its just a model for the view you are showing.

ConfirmEmailViewModel :)

share|improve this answer
add comment

No I don't believe it is overkill. I've felt the same about view models for simple things in the past but it adds bits which are helpful, such as strongly typing and validation.

As Keith, I'd also call it ConfirmEmailViewModel.

share|improve this answer
add comment

I like to take an MVVM style approach to MVC, for example, I use:

public class Person { }

as my domain model, and

public class PersonViewModel { }

as my view model. The view model is expressly used with the Controller and View. I also tend to use a mapping framework quite a lot, so I might mock up something like

public PersonController(IViewModelService<PersonViewModel> viewModelService)
{
    _viewModelService = viewModelService;
}

public ViewResult Edit(int id) 
{
    PersonViewModel model = _viewModelService.Get(id);
    return View(model);
}

[HttpPost]
public ViewResult Edit(PersonViewModel model)
{
    if (ModelState.Valid)
    {
        _viewModelService.Update(model);
    }

    return View(model);
}

where the IViewModelService<PersonViewModel> service is responsible for mapping my view model back to my domain model Person.

share|improve this answer
add comment

I don't know ASP.NET, but isn't this the job of a view helper? Or an "HTML Helper" as they put it.

An HTML Helper is just a method that returns a string. The string can represent any type of content that you want. For example, you can use HTML Helpers to render standard HTML tags like HTML and tags. You also can use HTML Helpers to render more complex content such as a tab strip or an HTML table of database data.

I say don't create a "view model," instead create a view helper.

That is straight from: http://www.asp.net/mvc/tutorials/older-versions/views/creating-custom-html-helpers-cs

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.