asp.net-mvc-2

MVC2 Action to handle multiple models

℡╲_俬逩灬. 提交于 2019-12-24 19:02:13
问题 I've been looking around for an answer to this, which I can't believe hasn't been asked before, but with no luck I'm attempting here. I have a signup form which differs slightly based upon what type of participant the requester is. While writing tests for the solution, I realized that all actions did the same things, so I'm attempting to combine the actions into one using a strategy pattern. public abstract class BaseForm { common properties and methods } public class Form1 : BaseForm {

MVC 2.0 - different view based on URL with shared controls

烂漫一生 提交于 2019-12-24 18:43:23
问题 I have 2 master pages. One is intended to be shown in a normal standalone website. The other is to be used in external sites as an Iframe. I want to be able to show the normal page at http://example.com/home/index and the iframed version at http://example.com/framed/home/index I want to have controls that will postback to one controller so I don't have to duplicate logic, so they must be available in both the normal and iframed versions. My problem is that when I try and use areas, I just can

WCF Custom ServiceBehavior/InstanceProvider with parameterless constructor

99封情书 提交于 2019-12-24 15:45:52
问题 We're trying to use Dependency Injection for a WCF Service. The Service has a dependency on a Unity Container. The container is used to find the appropriate class that implements an IJob Interface (based on a JobKey parameter in the method call) and calls a method on it. The Service is being hosted in MVC2. I've omitted as much irrelevant stuff as possible from the snippets below. Full code available if required... What I've done so far: Based on this MSDN Article, I've created a custom

YUI DataTable in ASP.NET MVC 3

南楼画角 提交于 2019-12-24 12:43:10
问题 I am using ASP.NET MVC 3. I am trying to populate my YUI data table with data from my database. In my view I have the following code snippets: @model IEnumerable<MyProject.News> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <link href="http://yui.yahooapis.com/2.8.2r1/build/reset-fonts-grids/reset-fonts-grids.css" rel="stylesheet" type="text/css"> <link href="http://yui.yahooapis.com/2.8.2r1/build/base/base-min.css" rel="stylesheet" type="text/css"> <link href="http://yui

ASP.Net MVC 2 - better ModelBinding for Dictionary<int, int>

落爺英雄遲暮 提交于 2019-12-24 12:13:59
问题 In some special cases you will need a list of textboxes (to deal with n - n associations) whose id is not know before runtime. Something like this : http://screencast.com/t/YjIxNjUyNmU In that particular sample I'm looking to associate a count to some of my 'templates'. in ASP.Net MVC 1 I coded a Dictionary ModelBinder to have a clean and intuitive HTML. It allowed things like this : // loop on the templates foreach(ITemplate template in templates) { // get the value as text int val; content

Customize URL in MVC not working

落花浮王杯 提交于 2019-12-24 11:37:35
问题 I am new in Asp.net MVC. I am struck at my Customize URL Routing problem. I have created my Controller named "Customer" and action as "DisplayCustomer". In Global.asax.cs page, using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace MvcApplication1 { // Note: For instructions on enabling IIS6 or IIS7 classic mode, // visit http://go.microsoft.com/?LinkId=9394801 public class MvcApplication : System.Web

json TimeSpan return object

半腔热情 提交于 2019-12-24 11:35:50
问题 I work with Asp.net MVC4 (C#), I want to load data from controller to view. from controller return an object in view, this object has an attribute of type TimeSpan (HH:DD:MM) this is my function: public JsonResult Buscar(string id){ string Mensaje = ""; Models.cSinDenuncias oDenuncia = new Models.cSinDenuncias(); oDenuncia.sd_iddenuncia = id; var denuncia = Servicio.RecuperaDenuncia<Models.cSinDenuncias>(ref Mensaje, oDenuncia.getPk(), oDenuncia); return Json(denuncia); } denuncia.sd

Spark View Engine with custom HTML Helpers

匆匆过客 提交于 2019-12-24 11:27:26
问题 I've added some of my own helpers to the System.Web.Mvc within my project and got it working with the default asp.net mvc view engine. By defining the helper like namespace System.Web.Mvc { public static class XSSHelper { public static string h(this HtmlHelper helper, string input) { return AntiXss.HtmlEncode(input); } public static string Sanitize(this HtmlHelper helper, string input) { return AntiXss.GetSafeHtml(input); } public static string hscript(this HtmlHelper helper, string input) {

HttpContext.Current.Session is null requesting images. Why?

拟墨画扇 提交于 2019-12-24 10:36:41
问题 I'm building a ASP MVC application. When I request a route to a controller, for example: http://myserver/sales/id/5 the session object HttpContext.Current.Session is working perfectly. However, when I'm requesting an image or a script, for example: http://myserver/Scripts/jquery-1.4.1.js the session object HttpContext.Current.Session is null How I can distinguish this situation from other when there is no "real" session (for example first login)? 回答1: Why would you need a session for

Ignore url values with Outputcache

こ雲淡風輕ζ 提交于 2019-12-24 10:27:46
问题 When I use outputcaching on an action method it is cached by full url, what i would like to do is cache the page but ignore some parts of the url. Custom route defined in Global.asax: routes.MapRoute( "Template", "Report/{reportid}/{reportname}/Template/{templateid}/{action}", new { controller = "Template", action = "Index" } ); My template controller public class TemplateController : Controller { [OutputCache(Duration=60*60*2)] public ActionResult Index(Template template) { /* some code */ }