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
Generally it's different perspectives over the same base model, but there are things I want to include/exclude per UI for security and performance reasons.Will that be because of restrictions imposed by the framework, or design?![]()
public class EnterTelephoneModel
{
[Required]
[DisplayName("Telephone Number")]
[DataType(DataType.PhoneNumber)]
[PhoneNumber(ErrorMessage="Phone number is not valid")]
public string TelephoneNumber { get; set; }
}
[HttpPost]
public ActionResult EnterTelephoneNumber(EnterTelephoneModel model)
{
if (ModelState.IsValid)
{
return Redirect(SuccessfulRedirectUrl);
}
ModelState.AddModelError("TelephoneNumber", "Not a valid number");
return View(model);
}
[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);
}
}