asp.net-mvc-2

Asp.Net MVC 2 Html.TextBoxFor Best way to specify a format string for a DateTime property of model

醉酒当歌 提交于 2019-12-02 18:15:55
As the question title explains, what is the best way to specify a format which my Views use when displaying values of a DateTime property via the Html.TextboxFor method. The default display includes the Date and Time where I really only want the Date displayed. Thanks In your model definition add the DisplayFormatAttribute to the DateTime property: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")] public DateTime Date { get; set; } Then in your View call: <%=Html.EditorFor(m => m.Date)%> If all goes well you should get a TextBox with the value filled in in the

Where is the best place to map from view model to domain model?

假如想象 提交于 2019-12-02 17:41:52
Where is the best place to do mappings from view model to domain model? By mappings I mean from my EditGrantApplicationViewModel to a GrantApplication object. Lets say that I have the following action method (partial code): [HttpPost] public ActionResult Create(EditGrantApplicationViewModel editGrantApplicationViewModel) { if (!ModelState.IsValid) { return View("Create", editGrantApplicationViewModel); } return View("Index"); } Do I need to pass editGrantApplicationViewModel to a service layer method and do the mappings in the method? You should not place any of your mapping logic inside the

Why really short timeout in ASP.NET MVC?

為{幸葍}努か 提交于 2019-12-02 17:34:40
I have an MVC 2 application where the timeout is set to 2880 (minutes as I understand it, but even if it is seconds there's a problem): <authentication mode="Forms"> <forms loginUrl="~/Account/LogOn" timeout="2880" /> </authentication> Now this should then mean 48 hours, or at least 48 minutes (if the value is seconds). But the user is logged out after as little as a couple of minutes of inactivity... Why is that? Any help appreciated! Found the answer finally after a lot of Googling... You have to set a custom machinekey in the web.config file. I used this generator: http://aspnetresources

ASP.NET MVC Login Modal problems - redirect goes to modal?

丶灬走出姿态 提交于 2019-12-02 17:20:01
问题 I have the login view showing up in a modal dialog (using jquery simplemodal), and when the user fails login - it works fine - the error goes back to the modal. The problem is when the user successfully logs in - the page is supposed to be redirected and the modal disappears, but the modal is now updated with the entire page :( In order for the modal to look correct - i check to see in the AccountController if the source of the login was Ajax, if so - return a partial view (to display in the

DisplayName metadata does not show up on view

大城市里の小女人 提交于 2019-12-02 17:07:36
问题 How will I show the correct DsiplayName on my view considering the following model. <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Project.Models.RegisterViewModel>" %> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <% using (Html.BeginForm()) {%> <table> <tr> <td class="label"> <%: Html.LabelFor(model => model.User.UserPrimaryEmail)%> </td> <td class="field"> <%: Html.TextBoxFor(model => model.User

Best practice for http redirection for Windows Azure

别等时光非礼了梦想. 提交于 2019-12-02 16:49:15
I have an azure website which is named: http://myapp.cloudapp.net Of-course this URL is kind of ugly so I set up a CNAME that points http://www.myapp.com to the azure url. All is well up until here, but there is a snag. http://myapp.cloudapp.net has leaked out and now is indexed by google and lives on other sites. I would like to permanently redirect any requests for myapp.cloudapp.net to the new home at www.myapp.com The website I have is coded in MVC.Net 2.0, as this is an azure app, there is not UI to access IIS and everything needs to be done in application code or web.config. What is a

Asp.net MVC Authorize attribute, redirect to custom “no rights” page

回眸只為那壹抹淺笑 提交于 2019-12-02 16:38:13
Asp.net MVC2 does redirect to login page with response 302 when authenticated user has no rights. I would like to split into two actions If user is not authenticated then do what it does, redirect to login page. If user is authenticated but has no required rights then return appropriate http status code and show no rights dude page. Is there any way to do it? Or am I doing something wrong with authorize and form authentication? Only way I can think of is by writing custom authorize attribute, which I want to avoid. You could write custom filter attribute like this: public class

Why is EditorFor in my ASP.NET MVC 2 application throwing ArgumentNullException?

家住魔仙堡 提交于 2019-12-02 15:51:13
问题 I have a weird problem with EditorFor in one of my views. The following code throws an ArgumentNullException. <%: Html.EditorFor(x => x.Name) %> However, the following code is fine. <%: Html.TextBoxFor(x => x.Name) %> Model.Name is a string variable - and it's set. EditorFor works in another view - until this view crashes, at which point then I have to restart the development web server (Cassini) or all the EditorFor calls crash with the same message. I ran a test with the MVC 2 source,

Creating child nodes for a DynamicNode in MvcSiteMapProvider that have dynamic parameters

落爺英雄遲暮 提交于 2019-12-02 15:39:00
I am using MvcSiteMapProvider 2.2.1 (http://mvcsitemap.codeplex.com), and am having a problem with creating children under a dynamic node (using a dynamicNodeProvider) when those children have a dynamic parameter (id). I am losing breadcrumbs for the following route: Stores/5/Products/Edit/23 where the url pattern is: Stores/{storeID}/{controller}/{action}/{id} It works fine when the ID is left out (ie the "New" action). But when the ID is specified, it doesn't match the route, and my breadcrumbs (using the SiteMapPath helper) is blank. My Sitemap: (abreviated) <?xml version="1.0" encoding=

jqGrid row update

感情迁移 提交于 2019-12-02 15:37:36
问题 does anyone have a link to an asp.net mvc 2 c# sample which contains saving rows to the server? how do you post the results back to a db? 回答1: Check out those two sample applications: jqGrid in ASP.NET MVC 3 and Razor jqGrid in ASP.NET MVC - Strongly typed helper 来源: https://stackoverflow.com/questions/5335766/jqgrid-row-update