asp.net-mvc

Processing ASP.NET expressions inside an external Javascript file...

Hi, What's the best practice for using ASP.NET expressions inside an external Javascript file? I'm using the ASP.NET MVC framework currently and need to do something similar to the following from within an external JS reference: jQuery(document).ready (function () { jQuery ("#element<%= Model.IdFromAThing %>").click (... blah ... ...

Using custom ModelBinder to have strongly typed TPH models in controller actions-- is this smelly?

Here's a little background on my solution: ASP.Net MVC app Using Linq-to-SQL with table-per-hierarchy inheritance Using DataAnnotationsModelBinder as default So I have a Device abstract class and then a series of derived classes (ServerDevice, DiskDevice, PSUDevice, etc) that inherit from it in the proscribed Linq-to-SQL way. I have...

Calling a javascript function with a parameter retrieved from the model in ASP.NET MVC

I have a javascript function that I need to call inside my body tags. My javascript fuction looks like this: function NewExistingPicture(pictureName) { //code for javascript function } And this is what I'm trying to do in HTML: Existing Photos: <% foreach (var Photo in Model.ProductThumbnails) { %> NewExistingPicture(<...

Best place to put my IRouteConstraint implementations in ASP.NET MVC?

In an ASP.NET MVC project, where is the best place to put my classes that implement IRouteConstraint in order to keep it organized and stay true to the structure of the project? ...

jQuery $.getJSON works only once for each control. Doesn't reach the server again.

First my code $.getJSON("./posts/vote/" + postId + "/1", null, function(result) { if (result.result == true) $("#pst" + postId + " > .pstside > .rank > .score").html(result.voteCount); }); I have a bunch of buttons each with code which brings some voting results from an ASP.Net MVC controller action. This works well the fir...

How to group partial shared views for specified controllers?

Is it possible to tell ViewEngine to look for partial shared views in additional folders for specified controllers (while NOT for others)? I'm using WebFormViewEngine. This is how my PartialViewLocations looks at the moment. public class ViewEngine : WebFormViewEngine { public ViewEngine() { PartialV...

In ASP.NET MVC, why do I get 404 errors after Publishing my website?

I'm still new to ASP.NET MVC and I'm struggling a little with the routing. Using the ASP.NET development server (running directly from Visual Studio), my application can find its views without any problems. The standard ASP.NET URL is used - http://localhost:1871/InterestingLink/Register However, when I publish my site to IIS and acces...

Asp.net Mvc: Dynamic page title

Hello, in webforms I would always use my masterpage to set page titles and meta description based on the current url. I was thinking of doing the same for my Asp.net Mvc projects but I ain't sure where to start. It would be nice to be able to set the title/description based on the controller and/or action with some default values incase ...

ASP.NET MVC custom helper objects

Hi, I'm going to write a ton of helpers for my app. For many of them I'd like not to extend HtmlHelper, but to create another helper class instead, for two reasons: 1) to be able to write, say, Link.Home and Icon.Edit instead of Html.HomeLink and Html.IconEdit; 2) to be able to easily tell standard helpers from custom ones and where t...

MVC 1.0 installation problem.

Hi, I have Visual Studio 2008 Team System with Framework 3.5 and SP1. I downloaded MVC framework 1.0 from the following location http://www.microsoft.com/downloads/details.aspx?FamilyID=53289097-73ce-43bf-b6a6-35e00103cb4b&amp;displaylang=en and installed it. But after installation there was no MVC project template added to Create new W...

ASP.net MVC AntiForgeryToken over AJAX

I am currently developing an MVC application in ASP.net. I am using AJAX.ActionLink to provide a delete link in a list of records, however this is very insecure. I have put this: <AcceptVerbs(HttpVerbs.Post)> Over the function to do the deleting, which stops the function being called simply by a URL. However, the other security hole t...

ASP.NET MVC how to create a model which pulls in data from 2 tables, to display in 1 view

I think this may be a very simple question, but I am only just starting out with .net and c# at all, and only really just finally getting my head around OO stuff. I have built the NerdDinner application, and I am building on top of it currently with my own project. What I need to do, in the context of nerd dinner, is display the detail...

Where and why asp.net changes error response?

I want my ASP.NET MVC application return HTTP response with code 400 and description of the error as body. My code is: response.StatusCode = 400; response.Write("Some error"); response.End(); When I test this code on localhost, I get expected result. But on remote server, response text contains just text description of the error, in t...

Data Caching Stores In ASP.NET MVC

Greetings fellow earthlings. I'm researching methods of caching data retrieved from various database tables using ASP.NET MVC. We have a huge amount of data which is only updated once a day and from then on is static. This can vary but generally it's things like a list of users (employees), to departments, offices, locations we're in ...

Ignoring a route in ASP.NET MVC results in a 200 not a 404

We have URLs of the form http://site/controller.mvc/action If we accidentally write a relative URL for an image into the html (say src="imgs/img1.gif") this results in the browser making a request to: http://site/controller.mvc/action/imgs/img1.gif Which gets routed through to the controller but then cannot resolve to an action me...

How do i get the url part after a "#" from HttpRequestBase

i am receiving GET requests like this http://localhost/controller/List#SearchGuid=755d259d-e7c9-4c5a-bf2a-69f65f63df8d and i need to read the SearchGuid which is after the #. unfortunately the HttpRequestBase seems the hide everything past a #. does somebody know how i could still read the SearchGuid from within the controller action?...

How can I change the look of an ASP.NET page without recompiling code?

I am looking at taking on a new web development project and the customer has two big specifications the first is that they want it developed in .NET and the second is that they want to be able to change the look and feel of the page without having to recompile code. While I am new to ASP.NET I am familiar with the concept of Model View ...

ASP.NET MVC - Regex for a URL Slug

hello, I am writing a URL Slug for routing. Should I leave the slug constraint blank or what? Here is my code: routes.MapRoute( null, "q/{slug}/{id}", new { controller = "q", action = "Index" }, new { id = @"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-f...

ASP.NET MVC: Not executing actionfilters on redirect and throw HttpException

Hi, I've created an OnActionExecuted filter to populate some viewmodel attributes with data from db (I'm not using ViewData["somekey"], preferring many ViewModels descending from a common ancestor). public class BaseController : Controller { protected DataClassesDataContext context = new DataClassesDataContext(); protected ove...

StringTemplate for runtime code gen?

Hi, I am working on a project that generates code at runtime based on meta-model. I've used vb.net xml literals for this, but today I ran accross StringTemplate project. Has anybody successfully used this library in C# project. ...