asp.net-mvc

asp.net mvc: page with multiple forms -> submit -> show errors scenario

I have a page with multiple forms which can be handled by different actions and controllers. When submitting form with wrong data action method have to render the entire initial page + error messages. I'm facing the problem when action method which is responsible only for his own small task have to deal with rendering the entire initial ...

C#/MVC and RedirectToAction behaviour

I've created MVC2 based solution in VS2010 using standard template. Site.Master is cleaned a bit, here is how HomeController looks like: namespace MvcApplication1.Controllers { [HandleError] public class HomeController : Controller { public ActionResult Index() { return RedirectToAction("About"); ...

Why JSON empty string deserializes to null at the server side ?

Hello, I'm sending empty string through $.post and it deserializes to null. How to differentiate if the string was empty or null at the client side ? Regards UPDATE What I'm actually doing is: $.post("Controller/Action", $.param({Name: ""}, true), null, "json"); at the server: public Container { public string Name; } public v...

asp.net mvc regular expression phone

[RegularExpression(@"^[a-zA-Z0-9_,:- ]*", ErrorMessage = "Phone can Contains only Only Alphanumeric Characters ")] How can I validate accomodate () ' in the above regular expression, it is giving a parsing error. ...

Detail view list from multiple tables(ASP MVC)

I have a page with a list of devices. Every device has a detail page. What i'm trying to achieve is get a list of all projects belonging to a device on the device detail page. A device can have several projects, and a project can also be linked to several devices (many-to-many relation). I have a table in my database to link the device a...

How do i use System.Net.NetworkInformation.GatewayIPAddressInformation Class?

I tried every trick in the book, creating a new object, instantiating it (even tho it says i can't) and just trying to create a reference to use it, and then also trying to call the .Address value inside it while using it like i would use a shared member (without instantiation) and nothing is working, msdn sample/help is useless... i eve...

Unit Testing Action Filters - How to mock ViewResult

I did a search on SO and looks like this question gets asked quite often. I have been able to get the mocks working and I'm also able to execute OnActionExecuted() without any issues. Here's my Unit Test. The commented lines are the ones that fail and I'm sure I'm not mocking the right type. //Arrange //var viewResult = ...

Unable to successfully receive JSON data to .NET MVC Controller

Hi, I'm aiming to build up a JSON array of mouse positions and pass them to a controller. For some reason my json is returning from the controller as undefined can anyone spot my problem? // Attempt at declaring a JSON object var personResults = { "answers": [] }; // Onclick I fire in values from mouse event personResults.answers[cou...

nested set and treeview control

Hi All, Given the following database tables and sample data: Locations Id ParentId LeftIndex RightIndex Description -- -------- --------- ---------- ----------- 34 2 85 104 Florida Region 73 34 94 95 Miami Products Id ParentLocationId Code Description -- ---------------- -...

Why is my MVC viewModel null?

I'm trying to pass a viewModel to an edit form view. The issue is that I instanciate the model and assign values to it, but the model remains null. My Action: public ActionResult OrderEdit(takeOrder FormInput) { takeOrder viewModel = new takeOrder { Name= "anonymous", TableNumber = 13, ...

Structuring of Asp.net MVC controller folders for better cohesion

When building complex applications the controllers can start to get unwieldy and very large, which may mean that you split them out into separate controllers. This may not be suitable as it will be reflected in the users experience. Ie. They will see the controller name in the URI. For example: The default project that ships with MVC ha...

How to update a div with Ajax.BeginForm AND execute a javascript function?

I am updating a div with a partial view by using something like this: <% using (Ajax.BeginForm("Action", "Controller", new { id=Model.id }, new AjaxOptions { UpdateTargetId = "divId", InsertionMode = InsertionMode.InsertAfter, })) { %> ...

ASP.NET MVC: How can I pass a querystring variable

I've worked on web forms for a while and am not used to mvc. Here is what i want to do: <% if guest tehn %> URL.RouteURL("AcccountCreate?login=guest") <% end if %> However I can't do this because it says a route with this name has not been created. And I am assuming it would be silly to create a route for this. ...

How to manage conditional enable/disable state on a mvc form?

I'm building a form with many panels and many controls (both inside and outside the panels). Panels and controls have to be enabled/disabled for edition (and probably disabled for edition with the last selected value) depending on model state, other panel's state and their own business rules validation. Until now, we have created many pa...

Easy way to maintain scroll position with ASP.NET MVC2?

I was wondering if there was a way to easily maintain scroll position using MVC? I've seen a few ways of doing it with javascript, but I would like an easy way like webforms, such as the MaintainScrollPositionOnPostBack page property. Does such a thing exist or am I going to have to use javascript? ...

ASP.NET MVC: Getting ViewModel into partial view on ViewPage

I have a ViewPage, Index.aspx. In it, I have: <%= Html.Partial("~/Index/ViewUserControl/Promo.ascx, new PromoViewModel()); %> Now, the constructor for PromoViewModel requires a MemcachedCache object that the index's controller also uses. How should I pass this MemcachedCache into my partial view? Should I put the MemcachedCache inst...

How does ASP.NET MVC caching work for an AJAX request?

I'm just starting to look in to caching to improve performance and have a question about caching for an AJAX call. I have a action which is used to query twitter and then return the results. At the moment when a user presses a button it loads a rotating gif whilst it goes off to the action to do the query and then return a partial view....

.Net MVC Ajax and Scriptmanager conflict

Hello all, We have a simple ajax link (Ajax.ActionLink(...)) that has been working fine. Recently, another developer added some ajax-ey code to the same page that uses an asp scriptmanager ... now suddenly the first ajax link no longer works. More specifically we get the error : "sys.mvc.asynchyperlink' is null or not an object". Below ...

Invoking a method of a Generic Class

Here is the Context : I try to code a mapper for converting my DomainModel Objects to ViewModel Ojects dynamically. The problem I get, it's when I try to invoke a method of generic class by reflection I get this error : System.InvalidOperationException : Late bound operations cannot be performed on types or methods for which ContainsGe...

Get header values in ASP.NET MVC

Hi All, I have a requirement to capture the HTTP User Agent header coming in from a device, take the value and remove a 'uuid' This UUID can then be used to direct the device to the correct location to give it the files relevant to the device. In webforms I was able to get it using Request.ServerVariables["HTTP_USER_AGENT"]; //inside...