asp.net-mvc-2

ModelState.AddModelError - How can I add an error that isn't for a property?

久未见 提交于 2019-11-27 06:07:00
I am checking my database in Create(FooViewModel fvm){...} to see if the fvm.prop1 and fvm.prop2 already exist in that combination; if so, I want to add an error to the modelstate, then return the whole view. I tried: public ActionResult Create(FooViewModel fvm){ if (ThatComboAlreadyExists(fvm)) { ModelState.AddModelError("Model", "There is already one like that"); return View(fvm); } } ...but I get no display of errors in the Html.ValidationSummary , which is where I assume they would appear. I have the suspicion that "Model" is not the right key, but I haven't been able to find anything a la

ASP.NET MVC 3 Custom HTML Helpers- Best Practices/Uses

拈花ヽ惹草 提交于 2019-11-27 04:57:49
问题 New to MVC and have been running through the tutorials on the asp.net website. They include an example of a custom html helper to truncate long text displayed in a table. Just wondering what other solutions people have come up with using HTML helpers and if there are any best practices or things to avoid when creating/using them. As an example, I was considering writing a custom helper to format dates that I need to display in various places, but am now concerned that there may be a more

How do I configure ASP.NET MVC routing to hide the controller name on a “home” page?

不问归期 提交于 2019-11-27 04:56:43
Following on from this question: ASP.NET MVC Routing with Default Controller I have a similar requirement where my end user doesn't want to see the controller name in the url for the landing or "home page" for their application. I have a controller called DeviceController which I want to be the "home page" controller. This controller has a number of actions and I'd like to use URL's like the following: http://example.com -> calls Index() http://example.com/showdevice/1234 -> calls ShowDevice(int id) http://example.com/showhistory/1224 -> calls ShowHistory(int id) I also need links generated

Jquery dialog partial view server side validation on Save button click

♀尐吖头ヾ 提交于 2019-11-27 04:56:26
I have a table that displays data. Each row of table has Edit button. When edit button is clicked a jquery dialog appears with Form for editing the user info and save and cancel button . The form is nothing but a partial view buttons are part of partial view. <button name="button" class="button" id="editCurrentRow" onclick="EditCurrentRow(@item.ID); return false;"> $("#editResult").dialog({ title: 'Edit Admin', autoOpen: false, resizable: false, height: 500, width: 600, show: { effect: 'drop', direction: "up" }, modal: true, draggable: true, open: function (event, ui) { $(this).load('@Url

Are <%: and <%= the same thing as embbed code (expression) blocks

旧街凉风 提交于 2019-11-27 04:44:42
Having just started with MVC 2 I notice that in their starter template they use <%: Html.ActionLink("Home", "Index", "Home")%> and I was sure that in MVC 1 it was <%= Html.ActionLink("Home", "Index", "Home")%> Are they the same thing? If so, why the change from equal sign to colon. the colon syntax means you'll be html encoded automatically: http://haacked.com/archive/2009/09/25/html-encoding-code-nuggets.aspx They couldn't just html encode all the existing <%= blocks, because things that are already properly encoded (which is hopefully most of the projects out there) would look strange. <%=

How can My Asp.Net C# class return a json format

爱⌒轻易说出口 提交于 2019-11-27 04:37:32
问题 How would like a class that will return a json format. This method work Great in the controller but when I want to put in a Class, the Json object don't seem to exist. public JsonResult Test() { //Error 1 The name 'Json' does not exist in the current context C:\inetpub\wwwroot\mvcinfosite\mvcinfosite\Validation\ValidationClass\BaseValidator.cs 66 20 mvcinfosite return Json(new { errMsg = "test" }); } I want to put that code in a simple class. I want be able to call this method in many

Validating required selection in DropDownList

天涯浪子 提交于 2019-11-27 04:36:38
问题 My view model defines property which has to be displayed as combo box. Property definition is: [Required] public int Processor { get; set; } I'm using DropDownListFor to render combo box: <%=Html.DropDownListFor(r => r.Processor, Model.Processors, Model.Processor)%> Model.Processors contains IEnumerable<SelectListItem> with one special item defined as: var noSelection = new SelectListItem { Text = String.Empty, Value = "0" }; Now I need to add validation to my combo box so that user must

How to pass additional postdata into an add record function - JQGrid - MVC . NET

回眸只為那壹抹淺笑 提交于 2019-11-27 04:32:48
问题 I am using the JQGrid plugin on an MVC project. I am trying to avoid using 'Session'. I have been able to pass extra postdata into my edit and delete functions, using the serializedata methods from JQGrid. E.G. serializeEditData: function (postdata) { var rowdata = jQuery('#gridId').getRowData(postdata.id); return {id: postdata.id, oper: postdata.oper, SomeExtraData: $('#extradata').val()}; } However, there doesn't appear to be a serializeAddData function. Is there another way to alter the

When `PostAuthenticateRequest` gets execute?

大城市里の小女人 提交于 2019-11-27 04:26:04
This is my Global.asax.cs file: public class MvcApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { ... } protected void Application_Start() { this.PostAuthenticateRequest += new EventHandler(MvcApplication_PostAuthenticateRequest); } // This method never called by requests... protected void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e) { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value

The Purpose of a Service Layer and ASP.NET MVC 2

China☆狼群 提交于 2019-11-27 04:14:11
问题 In an effort to understand MVC 2 and attempt to get my company to adopt it as a viable platform for future development, I have been doing a lot of reading lately. Having worked with ASP.NET pretty exclusively for the past few years, I had some catching up to do. Currently, I understand the repository pattern, models, controllers, data annotations, etc. But there is one thing that is keeping me from completely understanding enough to start work on a reference application. The first is the