asp.net-mvc

Building pages with multiple views

I'm looking to build an ASP.NET MVC application where many screens will have multiple distinct views. Ideally the user would be able to bring the items they require into their workspace page in a portal style. Even if that is not possible, there would need to be a number of common items joined in various ways for various classes of user:...

chart stream not rendering correctly

Hey All, My controller, in a nutshell is this: chart1.SeriesCollection.Add(SC); using (MemoryStream ms = chart1.GetChartStream()) { return File(ms.ToArray(), "image/png"); } My view is this: $('#targetDiv').load("Home/GetImage"); And I'm getting garbled characters when rendered. ...

Why can't an asp.net mvc strongly typed view use an interface?

Why can't I use this interface to create a strongly typed view? public interface IAmAnAsset { int assetID { get; } String assetTag { get; set; } int? AddedBy { get; set; } DateTime addedDate { get; set; } int? LocationId { get; set; } DateTime? purchasedDate { get; set; } int? purchasedby { get; set; } Da...

Using MVC Contrib FluentHtml in Views

If I understand things correctly, to use MVC Contrib's FluentHtml in my Views, I need to change my Views to inherit from MvcContrib.FluentHtml.ModelViewPage instead of System.Web.Mvc.ViewPage. Will I lose any functionality provided by System.Web.Mvc.ViewPage if I do that? ...

Access nested properties with dynamic lambda using Linq.Expression

Let's assume that I have two classes: class person { int ID string name Address address } class address { int ID string street string country } These classes are more or less given, they are mapped via nHibernate to be honest :) In a grid (datatables.net as base) I would like to have a type-independent sorting...

Should a view be dependent on its controller? (ASP.NET MVC)

Hi all, Have a question about the design/usage of asp.net mvc here. In the html helper class, you can get to the current controller by Html.ViewContext.Controller. Moreover, you can get to the request, route collection and much more from the html helper class. Doesn't this go against the rule of MVC? Doesn't this opens up a ways for...

ASP.NET MVC, MVVM and file uploads...

Hi, I'm big fan of the MVVM pattern, in particular while using the ASP.NET MVC Framework (in this case v2 preview 2). But I'm curious if anyone knows how to use it when doing file uploads? public class MyViewModel { public WhatTypeShouldThisBe MyFileUpload { get; set; } } ...

How can I convert select list items to lowercase in C#?

I need to convert a select list (which is populated by a data feed) into lower case, I have traced as far some code in the relevant controller; private SelectList getAddressCountriesListDD() { var addressCountries = myOPG.AddressCountries; return new SelectList(addressCountries, "key", "value", "GBR"); } The myopg part is the ...

How to reference field value in ViewData.Model by the fields string name.

I have a FormViewModel that includes a LINQ to SQL resultset, and a List object. The resultset is a set of all possible field values that can be displayed in the view. These are Model.AllFields.Field1, Model.AllFields.Field2, ... There is a List (Model.UserFields) that contains the string names of a subset of the fields in AllFields t...

In ASP.NET MVC, how can I rewrite from /somepage to /pages/showpage/somepage?

How can I rewrite a url like: /SomePage to /Pages/ShowPage/SomePage? I tried: routes.MapRoute("myroute", "{id}", new { controller = "Pages", action = "ShowPage" }); But It's not working. What am I doing wrong? ...

Are ASP.NET controllers guaranteed to be used only once per request?

If we want to create some objects to be used by all action methods in a controller, can we store them as instance variables in the controller? Phil Haack mentions that controllers are not meant to be reused in this old post: http://stackoverflow.com/questions/222300/asp-net-mvc-beta-previous-routedata-overrides-current-routedata But ...

Is there any way to debug a call coming from an AJAX post?

Is there any way to debug a call coming from an AJAX post? This jQuery fires when the user hits OK: $.post( "/Detail/Copy", { bpid: $("#benefit_plan_id").val(), year: $("#copyYear").val(), plan: $(this).val() }, function(data) { } ); If I put the breakpoint in my controller: <AcceptVerbs(HttpV...

How can I remove repeated code in my actions?

I have the following code repeated several times in a mvc app. public ActionResult AnAction(int Id) { var claim = GetClaim(Id); if (claim == null) { return View("ClaimNotFound"); } // do stuff here .... return ....; } So far this pattern is use...

Call a JavaScript function from a texbox that is generated by an MVC Helper.

How do I call a JavaScript function from a texbox that is generated by an MVC Helper. I want my textbox to call a function like this: <input type="text" id="Ejemplo" onkeyup="SumaEjemplo()" /> I'm using: <%= Html.TextBox("Ejemplo")%> Where do I put it? ...

Modular Architecture - ASP.NET MVC

I've searched (google and SO) about this topic and couldn't find a thorough answer to my question(s). I'm building an ASP.NET MVC 2 application that will be distributed to other people (with source code). These people will need to create modules/plugins that use the application's base. The base is a simple ASP.NET MVC Application with ...

ASP.net MVC v2 - Debugging Model Binding Issues - BUG?

Hi guys I am having more than a little difficulty trying to debug why MVC is not binding correctly in a given case I have... Basically, I have my action which receives a complex object which in turn has a complex child object - Activity.Location.State (Where Activity is the complex object that the action expects, Location is a complex ...

User HTML Helper to populate a DropDown list

I'm trying to populate a dropdown list with a list returned by a query to my object's facade. I've seen a couple examples here but nothing close enough to my use case. Seems like: <%= Html.DropDownList("User.Affiliate", UserFacade.Instance.SelectAffiliates())%> should work but doesn't. ...

HttpCookie with Expires set returns DateTime.MinValue

I'm seeing something of an oddity when setting a cookie... Action: string cookieName = "foo"; string cookieValue = "bar"; //Set a cookie in the response, along with the Expires. this.ControllerContext.HttpContext.Response.Cookies.Add( new HttpCookie(cookieName, cookieValue) { Expires = DateTime.Now.AddHours(1) } ); When de...

Working example for JavaScriptResult in asp.net mvc

Can somebody provide a working example of JavaScriptResult in asp.net mvc. I understand that it returns javascript which is then executed on the client side and also that the content type of the response is set to text/javascript. I need some working example to see this thing in action. ...

Localization Helper, How to retrieve values from javascript?

Hello guys, I used localization helper from Matt Hawley. It's really working great. I have a problem though in getting the values on javascripts/jquery. I can't retrieve the resources text using this: example: alert('<%=Html.Resource(\"Strings,SomeKey\")%>'); Any help is greatly appreciated. Best ...