asp.net-mvc

ViewModel Single root inheritance hierarchy or ViewData injection with FilterAttributes

On a previous project I used single root inheritance for my MVC viewModel. Everything worked and was effective at giving data to the Site master, but was a bit of a pain in the controller actions. To properly construct the root view data each time, we had to override (using method hiding) Controller.View(). I'm tempted to try attribut...

ASP MVC Url Format

Say you have a page that provides a list of songs depending on some identifier you have specified, such as a category it belongs to. You may have your URL formatted like so: http://mysite.com/songs/view/1 Now lets say you wanted to add paging, what is the best way to structure that URL and how does the action method work? I am assuming...

asp.net mvc webservice, how to call from widowsforms application?

Hi, I have a task to automate sending zipped file with serialized data from window application to web application, and there is my problem i don't know how exactly do this, can I from window app send zipped file to controller action which would accept that file and unzip it? Probably this files will be large and i know if do this by ft...

Language for controllers names in ASP.NET MVC

Should my controllers names be in my native language or in English? What is the current best practice? And if in English, how do I make sure that the urls stays in my native tongue? I know that my webapp won't be multilingual and I rather not write a lot of boilerplate. ...

Set focus on on ASP.NET MVC model errors

I've got a model that does some validation checking and adds the errors to ModelState: ViewData.ModelState.AddModelError("mycontrol", "message") They display fine on the view side, but is there a way to set the focus to the control that corresponds to the validation message? Right now, the page refreshes and stays at the top of the pa...

How do i unit test this business logic?

Hi folks, i have a method that does takes in a object and saves it to the database. But, before i save the object, i do the following... (psuedo code) if (IsAuthenticated) { foo.UserId = AuthenticatedUser.Id; } else { foo.AnonEmail = "Jon@World-Domination"; foo.AnonName = "Jon Skeet"; } try { _fooService.Save(foo); } catc...

ASP MVC JsonResult Date Format

Hi, I have a controller action that effectively simply returns a JsonResult of my model. So, in my method I have something like the following: return new JsonResult(myModel); This works well, except for one problem. There is a date property in the model and this appears to be returned in the Json result like so: "\/Date(1239018869048...

dateTime object in ASP.NET MVC

Has anyone successfully bound 2 textboxes to one DateTime property using the model binding in MVC, I tried Scott's method http://www.hanselman.com/blog/SplittingDateTimeUnitTestingASPNETMVCCustomModelBinders.aspx but was dissatisfied as this stops the HTML fields and Model properties having the same name (so the validation could not set ...

Fake a form submission with C# WebClient

I need to call a web and retrieve the resulting data from the model in my asp.net mvc application. When accessed on the web, the form looks like this: <form id="textEntryForm" name="textEntryForm" method="post" action="/project/evaluate_to_pdf"> <textarea id="p" rows="20" name="p" cols="132"/><br/> <input type=...

Howto create a (base controller) printer friendly version?

I working on a project and I would like to have a printer friendly version of the Views I have. Is there anybody who already did this and have some tips how to accomplish this? (what kind Routing is used, etc.) I was thinking of making a PrintController. In the ActionResult of a method in the PrintController to return a View with a spec...

ModelState.AddModelError encodes HTML

Hi I am noticing a weird issue when using ModelState.AddModelError to validate input on my forms. The output from Html.ValidationMessage is not the true HTML value but it's encoded value and so the CSS style is not applied to the error message. Example: private string errorMessage = "<span class=\"negative\">{0}</span><br class=\"hid\...

ASP.NET Mvc - System.Web.Compilation.CompilationLock

I'm attempting to unit test some code using NUnit. I have a method: public static string RenderRoute(HttpContextBase context, RouteValueDictionary values) { var routeData = new RouteData(); foreach (var kvp in values) { routeData.Values.Add(kvp.Key, kvp.Value); } string contr...

When to use UserControls in ASp.Net MVC

Except for the purpose of reuse if repeating for more than one webpage, do usercontrols in this model offer any other advantage? ...

Is really impossible to write code in an mvc master page?

All I want to do is to write something like <%=Html.ScriptInclude("~/Scripts/jquery.1.2.6.js")%> When I do that I get an error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>) I'm using ASP.NET MVC Release Candidate 1. Is that impossible to accomplish? ...

DropDownList in conjunction with file upload in asp.net mvc

I have a file upload function in my asp.net mvc application that allows users to upload an xslx file containing data that should be persisted to a database. That data can be related to one of many categories. I need to be able to discern which category the data that is coming in is supposed to be related to, so I thought that a drop down...

TinyURL like routing with ASP.NET MVC?

I'm attempting to write a TinyURL like clone in ASP.NET MVC as a first project to get used to the framework. The URL routing is still a little confusing for me, especially when I deviate from the controller/action/id. Can any of you ASP.NET MVC ninjas help me setup a simple URL route similar to how TinyURL.com processes its routes? ...

Injecting Javscript into a page

I'm writing a web-based game that involves clicking links on various sites on the internet. I know it sounds strange but the basic premise is that you start on my page where you click a link to some page on another site. You continue to follow links until you get to the page you are trying to reach. Think WikipediaGame.org. The differenc...

asp.net mvc does it handle all requests? - iis 7 integrated mode

I have a site built using asp.net mvc running on IIS 7 using integrated mode. I noticed when I type in mysite.com/test.html I get back The IControllerFactory did not return a controller for a controller named 'test.html'. What I should have gotten was a 404 error and this should of been served by the IIS7 Static Handler. Now what I am...

Dynamic sitemap in ASP.NET MVC

I'm trying to create an automatic sitemap ActionResult that outputs a valid sitemap.xml file. The actual generation of the file is not a problem, but I can't seem to figure out how to populate the list of URL's in the system. Here is the code I have so far: public ContentResult Sitemap() { XNamespace xmlns = "http://w...

ASP.NET MVC "Stock Application" Deployment Issue

I am starting to learn ASP.NET MVC. I have deployed the "stock" ASP.NET MVC Sample Application (i.e. the simple user account system) to have a live version to test against when I start to play. Note that I'm using: - ASP.NET MVC 1.0 release. - WebFusion Host. I think the issue is to do with accessing the database. I deployed usin...