asp.net-mvc-2

How to use Bind Prefix?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 17:26:14
Say if I had this table in my db: Product It had ProductId ProductName ProductType Now for whatever reason I can't name my textboxes ProductName and ProductType so now my View Method would look like this public ViewResult Test([Bind(Exclude ="ProductId")] Product) So now through my playing around nothing would be matched in this product since they have different names. So I guess this is where Prefix would come in but I don't know how to use it. Nor how do I use it and Exclude at the same time. Can someone give me an example? The prefix is used as follows if in your view you have... <select

Set Timeout For Controller Action

回眸只為那壹抹淺笑 提交于 2019-11-26 17:24:54
问题 I have come across this thread already, but I might need something else for my situation. I have an action that returns a ViewResult , which is called by the client's $.post() JavaScript: var link = 'GetFoo?fooBar=' + fooBar; var jqxhr = $.post(link, function (response) { $('#myDiv').replaceWith(response); }); Controller: public ViewResult GetFoo(String fooBar) { if (Request.IsAjaxRequest()) { // perform a ridiculously long task (~12 minutes) // algorithm: 1) download files from the Azure

Challenges with selecting values in ListBoxFor

核能气质少年 提交于 2019-11-26 17:22:49
Working on my first ASP.Net MVC2 web app recently, I came across some issues when I needed to select multiple values in a list box. I worked around it with some jQuery, but went ahead and put together some very simple code to demonstrate. I'm using EF for the model, with two entities - Customers and HelpDeskCalls: Controller: public ActionResult Edit(int id) { Customer currCustomer = ctx.Customers.Include("HelpDeskCalls").Where(c => c.ID == id).FirstOrDefault(); List<HelpDeskCall> currCustCalls = (ctx.HelpDeskCalls.Where(h => h.CustomerID == id)).ToList(); List<SelectListItem> currSelectItems

EditorFor() and html properties

余生颓废 提交于 2019-11-26 17:06:52
Asp.Net MVC 2.0 preview builds provide helpers like Html.EditorFor(c => c.propertyname) If the property name is string, the above code renders a texbox. What if I want to pass in MaxLength and Size properties to the text box or my own css class property? Do I need to create one template for each size and length combinations in my application? If so, that doesn't make the default templates that usable. In MVC3, you can set width as follows: @Html.TextBoxFor(c => c.PropertyName, new { style = "width: 500px;" }) I solved this by creating an EditorTemplate named String.ascx in my /Views/Shared

How to use the plupload package with ASP.NET MVC?

让人想犯罪 __ 提交于 2019-11-26 15:26:23
问题 I am using plupload version 1.3.0 More specifically how I have to define my controller action to support chunking? Can I use the HttpPosteFileBase as a parameter? At the moment I am using the following code to initialize the plugin In the HEAD tag <link type="text/css" rel="Stylesheet" media="screen" href="<%: Url.Content( "~/_assets/css/plupload/jquery.ui.plupload.css" )%>" /> <link type="text/css" rel="Stylesheet" media="screen" href="<%: Url.Content( "~/_assets/css/plupload/gsl.plupload

Need an ASP.NET MVC long running process with user feedback

被刻印的时光 ゝ 提交于 2019-11-26 15:09:22
问题 I've been trying to create a controller in my project for delivering what could turn out to be quite complex reports. As a result they can take a relatively long time and a progress bar would certainly help users to know that things are progressing. The report will be kicked off via an AJAX request, with the idea being that periodic JSON requests will get the status and update the progress bar. I've been experimenting with the AsyncController as that seems to be a nice way of running long

ASP.NET MVC Model vs ViewModel

别等时光非礼了梦想. 提交于 2019-11-26 15:00:47
OK, I have been hearing discussion about "ViewModels" in regards to MS's ASP.NET MVC. Now, that is intended to be a specific kind of Model, correct? Not a specific kind of View. To my understanding, it's a kind of Model that has a specific purpose of interacting with the View? Or something like that? Some clarification would be appreciated. Essentially Model and View Model are both simple classes with attributes. The main objective of these classes are to describe (to "Model") an object for their respective audiences that are respectively the controller and the view. So you are completely

Validation: How to inject A Model State wrapper with Ninject?

心不动则不痛 提交于 2019-11-26 14:59:12
I was looking at this tutorial http://asp-umb.neudesic.com/mvc/tutorials/validating-with-a-service-layer--cs on how to wrap my validation data around a wrapper. I would like to use dependency inject though. I am using ninject 2.0 namespace MvcApplication1.Models { public interface IValidationDictionary { void AddError(string key, string errorMessage); bool IsValid { get; } } } // wrapper using System.Web.Mvc; namespace MvcApplication1.Models { public class ModelStateWrapper : IValidationDictionary { private ModelStateDictionary _modelState; public ModelStateWrapper(ModelStateDictionary

RegularExpressionAttribute - How to make it not case sensitive for client side validation?

南楼画角 提交于 2019-11-26 14:13:14
问题 I have a string that I use for client side validation: private const String regex = @"^(?:\b(?:\d{5}(?:\s*-\s*\d{5})?|([A-Z]{2})\d{3}(?:\s*-\s*\1\d{3})?)(?:,\s*)?)+$"; I use this string in my [RegularExpression(regex, ErrorMessage = "invalid")] attribute. I know that the /i flag for a Javascript regex is used to make it case insensitive, but just tacking it on to the end of my regex (i.e. @"^....$/i" isn't working - the regex validation fails completely, regardless of what is entered (valid

Firefox 6 Infinite Page Refresh With Page With Hash Tags

被刻印的时光 ゝ 提交于 2019-11-26 14:04:09
问题 When Firefox updated to version 6 recently, a site I'm working on severely broke. The site operates normally when browsing to any page without a hash tag but if you try to navigate to a page with a hash tag (e.g. #test ) or refresh the page once a hash tag was applied, the page refreshes as quickly as it can infinitely. This is a Asp.Net MVC 2 site created around a year and a half ago. 回答1: Turns out, this is an issue with an old version of MicrosoftAjax.js (the one that comes installed with