ASP.NET MVC 2 - anyone using?

Caporegime
Joined
18 Oct 2002
Posts
29,493
Location
Back in East London
I'm trying out MVC2 to expand my skills in VS2010, and am wondering if anyone uses this and/or likes/dislikes it? :)

Are there alternatives to consider?

Just an open ended discussion, I'm not having any issues. :)
 
Just started playing with it, although I haven't really done much though.

The new areas look interesting, good for keeping controllers within the part of the site they're relevant to.
 
Yeah, I'm liking some of the improvements over ASP.NET MVC 1.0, e.g. quick/easy basic validation on the model through attributes, asynchronous controllers and the strongly typed html helpers. Still don't really like the default WebForms view engine so I always swap it out for Spark (their new one 'razor' looks good too, not sure when they're releasing it though).

The only other decent MVC framework for ASP.NET I've used was Castle Monorail but I haven't used it since ASP.NET MVC came out.
 
Last edited:
I'm not liking the ASP syntax (i.e. the <% %> stuff). Is there a different View model 'plugin'? Even a template engine of some description? :)

Would prefer a complete DOM generator, but hey.. can't have everything :) (Maybe I could start one! :p)
 
I'm giving serious thought at the moment to moving to ASP.Net MVC when we rewrite/reskin our ecommerce site at work soon. It seems to allow for far far more control over the markup the end user receives, which is a must when you need very good cross-browser compatibility.

One downside I see is that if you have multiple UIs like us (frontend, order management, crm like application, supplier order management), you'll have to do a fair bit of data model customization per UI.

akaksj
 
I like it, but don't have enough time to invest much effort into it - we currently use ASP.NET WebForms at work still and it looks like we're sticking with it for a while yet. I've also been looking at Ruby on Rails, which is also an excellent MVC framework on an open platform, but I really dislike the syntax Ruby uses - reminds me of VB (*shudder*). I'm too used to C syntax :)
 
I'm giving serious thought at the moment to moving to ASP.Net MVC when we rewrite/reskin our ecommerce site at work soon. It seems to allow for far far more control over the markup the end user receives, which is a must when you need very good cross-browser compatibility.

One downside I see is that if you have multiple UIs like us (frontend, order management, crm like application, supplier order management), you'll have to do a fair bit of data model customization per UI.

akaksj

Will that be because of restrictions imposed by the framework, or design? :)
 
Just spotted a rather annoying er.. annoyance. I've got the following model, with my own attribute:

Code:
public class EnterTelephoneModel
{
    [Required]
    [DisplayName("Telephone Number")]
    [DataType(DataType.PhoneNumber)]
    [PhoneNumber(ErrorMessage="Phone number is not valid")]
    public string TelephoneNumber { get; set; }
}
And the controller action for it:
Code:
[HttpPost]
public ActionResult EnterTelephoneNumber(EnterTelephoneModel model)
{
    if (ModelState.IsValid)
    {
        return Redirect(SuccessfulRedirectUrl);
    }

    ModelState.AddModelError("TelephoneNumber", "Not a valid number");

    return View(model);
}
And an integration tests for the controller, model and validation:
Code:
[TestClass]
public class EnterTelephoneNumberControllerTests
{
    private readonly EnterTelephoneNumberController _controller = new EnterTelephoneNumberController();
    private readonly EnterTelephoneModel _model;
    private ActionResult _result;

    public EnterTelephoneNumberControllerTests()
    {
        _model = new EnterTelephoneModel();
    }

    [TestMethod]
    public void TelephoneNumberShouldBeAtLeast8Digits()
    {
        SetTelephoneNumber("12345678");
        PerformEnterTelephoneNumber();

        AssertIsSuccessfulRedirect();
    }

    [TestMethod]
    public void TelephoneNumberCanHavePlusSymbolAtStart()
    {
        SetTelephoneNumber("+12345678");
        PerformEnterTelephoneNumber();

        AssertIsSuccessfulRedirect();
    }

    [TestMethod]
    public void TelephoneNumberMustBeNumeric()
    {
        SetTelephoneNumber("+abcdefghijklmnop");
        PerformEnterTelephoneNumber();

        AssertIsNotSuccessfulRedirect();
    }

    private void AssertIsNotSuccessfulRedirect()
    {
        Assert.IsNotInstanceOfType(_result, typeof (RedirectResult));
    }

    private void SetTelephoneNumber(string telephoneNumber)
    {
        _model.TelephoneNumber = telephoneNumber;
    }

    private void PerformEnterTelephoneNumber()
    {
        _result = _controller.EnterTelephoneNumber(_model);
    }

    private void AssertIsSuccessfulRedirect()
    {
        Assert.IsInstanceOfType(_result, typeof (RedirectResult));
        Assert.AreEqual(EnterTelephoneNumberController.SuccessfulRedirectUrl, ((RedirectResult) _result).Url);
    }
}

The TelephoneNumberMustBeNumeric test fails, but when I enter a non-numeric number on the form it fails validation.

Have I missed something, or have Microsoft once again proven they just don't get what testing is for?
 
Think you could try rhinomock for controller tests. http://www.ayende.com/projects/rhino-mocks.aspx

Personally mvc.net has been a breath of fresh air since previously i'd been using weforms for 5 odd years, but then i guess any other way to create web application would have been nicer. I shouldnt complain but the viewstate/page life cycle of webforms started to sadden me.
I dont think web forms should be forgotten after all they have there pros over mvc.net, and since vs2010/.net4 both technologies can work together within the same web app (was even possible before vs2010 but was more of a workaround).
 
Not sure how rhinomocks would help tbh. I'm not looking to mock anything, just get it to behave as it does when used "for real" :)

I prefer Moq to Rhino anyway. Rhino have allowed their API to become far too polluted :)
 
Back
Top Bottom