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. :)
 
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

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?
 
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 :)
 
Just spotted a couple more annoyances. They probably have workarounds, but I can't find any info on them as yet. :)

1. XML Processing Instructions seem to get removed from the markup. Namely, I want to include &lt;?xml version="1.0" encoding="utf-8"?&gt; at the top of all my pages, yet it never appears.

2. Multiple DataAnnotations and/or fields for Validation. Fails on the first, doesn't parse the rest. E.g. I put a RegularExpression and a StringLength validation attribute on one field, it will only ever report the error message for the first that failed, not both (if both fail) likewise for fields. If I have two fields that are validated, and both have invalid entries, only the first will report failure. (Only when using client validation it seems)

3. Some validation uses client, others don't. Some use "real time" validation (i.e. I don't need to click submit.. even if I want it to wait until I do!) and some don't use client validation at all and must be submitted. P.I.T.A.

:)
 
Last edited:
Posted about the XML PI on asp.net forums, but alas.. their forum is moderated and now I have to wait until a moderator OKs it. :(
 
Back
Top Bottom