asp.net-mvc-2

EditorFor() and html properties

吃可爱长大的小学妹 提交于 2019-11-26 05:14:22
问题 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. 回答1: In MVC3, you can set width as follows: @Html.TextBoxFor(c => c.PropertyName, new {

How to use Bind Prefix?

故事扮演 提交于 2019-11-26 04:44:01
问题 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

Using Tempdata in ASP.NET MVC - Best practice

主宰稳场 提交于 2019-11-26 04:32:59
I am using ASP.NET MVC 3 to build a web application. What I am trying to do is pass values between two controllers, though there are many ways to do this I am particular interested in using TempData for this. public ActionResult Action1() { string someMessage; Test obj = SomeOperation(); if(obj.Valid) { someMessage = obj.UserName; } else { someMessage = obj.ModeratorName; } TempData["message"] = someMessage; return RedirectToAction("Index"); } public ActionResult Index() { ViewBag.Message = TempData["message"] return View(); } So is the use of TempData here correct ? I mean under best

ASP.NET MVC Model vs ViewModel

孤者浪人 提交于 2019-11-26 04:08:56
问题 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. 回答1: Essentially Model and View Model are both simple classes with attributes. The main objective of these classes are to describe (to "Model") an

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

十年热恋 提交于 2019-11-26 04:08:35
问题 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 :

ASP.NET MVC and IE caching - manipulating response headers ineffective

余生颓废 提交于 2019-11-26 03:40:47
问题 Background I\'m attempting to help a colleague debug an issue that hasn\'t been an issue for the past 6 months. After the most recent deployment of an ASP.NET MVC 2 application, FileResult responses that force a PDF file at the user for opening or saving are having trouble existing long enough on the client machine for the PDF reader to open them. Earlier versions of IE (expecially 6) are the only browsers affected. Firefox and Chrome and newer versions of IE (>8) all behave as expected. With

Why would multiple simultaneous AJAX calls to the same ASP.NET MVC action cause the browser to block?

守給你的承諾、 提交于 2019-11-26 03:32:55
A few days back I asked this question: Why does $.getJSON() block the browser? I fire six jQuery async ajax requests at the same controller action pretty much all at once. Each request takes 10 seconds to return. Through debugging and logging requests to the action method I notice that the requests are serialised and never run in parallel. i.e. I see a timeline in my log4net logs like this: 2010-12-13 13:25:06,633 [11164] INFO - Got:1156 2010-12-13 13:25:16,634 [11164] INFO - Returning:1156 2010-12-13 13:25:16,770 [7124] INFO - Got:1426 2010-12-13 13:25:26,772 [7124] INFO - Returning:1426 2010

Making a Simple Ajax call to controller in asp.net mvc

拥有回忆 提交于 2019-11-26 03:19:44
问题 I\'m trying to get started with ASP.NET MVC Ajax calls. Controller: public class AjaxTestController : Controller { // // GET: /AjaxTest/ public ActionResult Index() { return View(); } public ActionResult FirstAjax() { return Json(\"chamara\", JsonRequestBehavior.AllowGet); } } View: <head runat=\"server\"> <title>FirstAjax</title> <script src=\"http://code.jquery.com/jquery-1.9.1.js\"></script> <script src=\"http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js\"></script> <script

Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable

送分小仙女□ 提交于 2019-11-26 03:01:27
I'm playing with the latest Entity Framework CTP 5 release and building a simple asp.net MVC blog where I just have two tables: Post and Comments. This is done entirely in POCO, I just need help on the DbContext part, where I need it to be unit testable (using IDbSet?) and I need a simple/generic repository pattern for add, update, delete, retrieval. Any help is appreciated. Thanks. Paul Start with you DbContext, create a new file called Database.cs: Database.cs public class Database : DbContext { private IDbSet<Post> _posts; public IDbSet<Post> Posts { get { return _posts ?? (_posts = DbSet

Showing Difference between two datetime values in hours

[亡魂溺海] 提交于 2019-11-26 02:51:32
问题 I am retrieving two date time values from the database. Once the value is retrieved, I need the difference between the two values. For that, I create a timespan variable to store the difference of the 2 date values. TimeSpan? variable = datevalue1 - datevalue2; Now i need to show the difference which is stored in the Timespan variable in terms of number of hours. I referred to TimeSpan.TotalHours but couldn\'t apply the same for some reason. How do I do that? I am using C# on a MVC project. I