jQuery Mobile/MVC: Getting the browser URL to change with RedirectToAction

I think I’ve found an answer. Buried deep in the jQuery Mobile documentation, there is information about setting the data-url on the div with data-role=”page”. When I do this, I get the nice jQuery Mobile AJAX stuff (page loading message, page transitions) AND I get the url in the browser updated correctly. Essentially, this is … Read more

Is it possible to display raw Html from database in ASP.NET MVC 3?

All you need is: @Html.Raw(yourEncodedHtmlFromYouDatabase) I’m assuming that the html in the database has been properly sanitized (or at least from a reliable source), because if not, you could be opening yourself up to cross-site scripting attacks. The reason your approach didn’t work is that Razor HTML-encodes output by default (every time you use @ … Read more

How to validate one field related to another’s value in ASP .NET MVC 3

One possibility is to write a custom validation attribute: public class RequiredIfOtherFieldIsNullAttribute : ValidationAttribute, IClientValidatable { private readonly string _otherProperty; public RequiredIfOtherFieldIsNullAttribute(string otherProperty) { _otherProperty = otherProperty; } protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var property = validationContext.ObjectType.GetProperty(_otherProperty); if (property == null) { return new ValidationResult(string.Format( CultureInfo.CurrentCulture, “Unknown property {0}”, new[] { _otherProperty … Read more

ASP.NET MVC 3: DataAnnotations.FileExtensionsAttribute not working

Since System.ComponentModel.DataAnnotations.FileExtensionsAttribute is sealed. I use a wrapper for MVC 4. public class HttpPostedFileExtensionsAttribute : DataTypeAttribute, IClientValidatable { private readonly FileExtensionsAttribute _innerAttribute = new FileExtensionsAttribute(); /// <summary> /// Initializes a new instance of the <see cref=”HttpPostedFileExtensionsAttribute” /> class. /// </summary> public HttpPostedFileExtensionsAttribute() : base(DataType.Upload) { ErrorMessage = _innerAttribute.ErrorMessage; } /// <summary> /// Gets or sets … Read more