asp.net-mvc-2

UIHint Attribute in MVC

僤鯓⒐⒋嵵緔 提交于 2019-11-26 19:51:35
问题 What is Use of UIHint Attribute in MVC . Can anyone please provide me a simple example of how to use it and what it does. 回答1: When using a Display or Editor template, UIHint will tell it which template to use: [UIHint("SomeTemplate")] public class MyViewModel { public string SomeProperty { get; set; } } If you create a Display template called SomeTemplate.ascx (since you are MVC2) in the Views/Shared/DisplayTemplates or Views/{Controller}/DisplayTemplates then it will use that template when

Implementing a Progress bar for long running task implemented with an ASP.NET MVC 2 AsyncController

醉酒当歌 提交于 2019-11-26 19:46:01
问题 After reading the documentation on AsyncControllers in ASP.NET MVC 2, I am wondering what's the best way to implement an ajax progress bar in this scenario. It seems a bit odd that the tutorial does not cover this at all. I guess implementing an AJAX progress bar involves requires additional action method that returns the status of the current task. However, I am not sure about the best way to exchange information on the status of the task between worker threads and that action method. My

RedirectToAction not working after successful jquery ajax post? [duplicate]

会有一股神秘感。 提交于 2019-11-26 19:34:54
问题 This question already has answers here : How can I RedirectToAction within $.ajax callback? (4 answers) Closed 6 years ago . The following does not redirect my page: Here is the MVC code: [HttpPost] public ActionResult GoHome() { return RedirectToAction("Index", "Home"); } Here is the ajax post: $.support.cors = true; $.ajax({ type: "POST", url: "http://localhost/UserAccount/GoHome", dataType: 'json', crossDomain: true }); The post is successful and when it hists the GoHome action it does not

Get [DisplayName] attribute of a property in strongly-typed way

こ雲淡風輕ζ 提交于 2019-11-26 18:56:52
问题 Good day! I've such method to get [DisplayName] attribute value of a property (which is attached directly or using [MetadataType] attribute). I use it in rare cases where I need to get [DisplayName] in controller code. public static class MetaDataHelper { public static string GetDisplayName(Type dataType, string fieldName) { // First look into attributes on a type and it's parents DisplayNameAttribute attr; attr = (DisplayNameAttribute)dataType.GetProperty(fieldName).GetCustomAttributes

Unit tests on MVC validation

旧街凉风 提交于 2019-11-26 18:49:47
问题 How can I test that my controller action is putting the correct errors in the ModelState when validating an entity, when I'm using DataAnnotation validation in MVC 2 Preview 1? Some code to illustrate. First, the action: [HttpPost] public ActionResult Index(BlogPost b) { if(ModelState.IsValid) { _blogService.Insert(b); return(View("Success", b)); } return View(b); } And here's a failing unit test that I think should be passing but isn't (using MbUnit & Moq): [Test] public void When_processing

Custom model validation of dependent properties using Data Annotations

拟墨画扇 提交于 2019-11-26 18:40:40
Since now I've used the excellent FluentValidation library to validate my model classes. In web applications I use it in conjunction with the jquery.validate plugin to perform client side validation as well. One drawback is that much of the validation logic is repeated on the client side and is no longer centralized at a single place. For this reason I'm looking for an alternative. There are many examples out there showing the usage of data annotations to perform model validation. It looks very promising. One thing I couldn't find out is how to validate a property that depends on another

How can I use Html.DisplayFor inside of an iterator?

吃可爱长大的小学妹 提交于 2019-11-26 18:20:00
问题 I am loving MVC 2. The whole thing just fits the web so well. There is one piece of functionality, however, that I am unable to coax out of the Html.DisplayFor() function: <@ Page Inherits="ViewPage<IEnumerable<Foo>>"> <% foreach(var item in Model) { %> <%: Html.DisplayFor(item.BarBaz) %> <% } %> I need to be able to use the DisplayTemplate for this value. Is there a way to do this? 回答1: Actually, I figured it out. How stupid of me. This works: <@ Page Inherits="ViewPage<IEnumerable<Foo>>"> <

asp.net mvc azure “Error accessing the data store!”

ぐ巨炮叔叔 提交于 2019-11-26 17:51:35
问题 I've started using the AspProviders code to store my session data in my table storage. I'm sporadically getting the following error: Description: Exception of type 'System.Web.HttpException' was thrown. INNER_EXCEPTION:Error accessing the data store! INNER_EXCEPTION:An error occurred while processing this request. INNER_EXCEPTION: ConditionNotMet The condition specified using HTTP conditional header(s) is not met. RequestId:0c4239cc-41fb-42c5-98c5-7e9cc22096af Time:2010-10-15T04:28:07

Can't get sql server compact 3.5 / 4 to work with ASP .NET MVC 2

会有一股神秘感。 提交于 2019-11-26 17:32:20
I'm using Visual Studio 2008 Pro. I'm probably missing something very obvious here, but I've been trying to get the CTP for Sql Server compact 4 to work in my asp.net mvc application. I can find next to no instruction on how to set this up or a working example application. My goal is a private install so I can just include it in my web app without having to do sql server setup on my domain hosting. This is really just me shooting the breeze and trying to figure this out. I don't plan to host a market or anything with this. So, I've copied all the dll's that install in the base 4.0 direction (c

How to create Custom Data Annotation Validators

耗尽温柔 提交于 2019-11-26 17:29:51
Wanting to create custom data annotation validation. Are there any useful guides / samples on how to create them? Firstly: StringLength with minimum and maximum length. I'm aware .NET 4 can do this, but want to do the same in .NET 3.5, if possible being able to define minimum length only (at least x chars), maximum length only (up to x chars), or both (between x and y chars). Secondly: Validation using modulus arithmetic - if the number is a valid length, I wish to validate using the Modulus 11 algorithm (I have already implemented it in JavaScript, so I guess it would just be a simple porting