asp.net-mvc

What is the best asp.net mvc code example ?

There are quite a few asp.net mvc code examples by different people at www.asp.net/mvc, based on your experience, what is the best code example, I mean, the example you can learn and follow mostly in your project. ...

Populating a generic ViewModel for building reports

I need to generate several reports, and many of them will simply be a table of entities from my database. The entities could be of any type, and I won't always need the entire entity. My current approach is to create a ViewModel that contains a field of type List<List<string>>, which represents my table, where each row is a List of cel...

ASP .Net MVC in VS2008 - published build appears differently

Hello When I run my MVC application through Visual Studio 2008, the website looks fine with regards to the styling, images, etc. But if I publish this build to a folder and use IIS to view it, the styling is all over place, and images are not right. Initially, I thought this was some error on my behalf with regards to the style she...

C# MVC: When to use a specific (non-default) ModelBinder?

It is my understanding that the default model binder is capable of turning <input type="text" name="myType.property1" value="John Doe" /> <input type="text" name="myType.property2" value="22" /> into: [AcceptVerbs(HttpVerbs.Post)] public ActionResult SomeAction(MyType myType) { // This will be "John Doe" String someNa...

How can I build a tabbed menu in ASP.NET MVC?

I would like to build a tabbed menu pretty similar to the profile management of StackOverflow. When you take a look at the url, it said: /users/flesym?tab=stats or ?tab=prefs. I was able to create the tabbed menu, but I'd like to know HOW can I call an action method and display the result depending the selected tab. I tried using a p...

Where can I persist what company a user belongs to with ASP.NET MVC and MembershipProvider?

When a user logs on to my ASP.NET MVC application I need to persist what company that user belongs to. The company they belong to will determine what database ~all~ their queries come from so it is important for me to query for their company as soon as they log in and persist it so I don't have to perform this lookup again. Where/How ...

C# MVC: Case for ModelBinder, or not? Looking for "cleanest" solution

Hello, I have a foreach based table in my MVC partial view: <% foreach (var item in Model) { %> <tr> <td><%= Html.Encode(item.FirstName) %></td> <td><%= Html.Encode(item.LastName) %></td> <td><%= Html.Encode(item.LastVisit) %></td> </tr> <% } %> Next to it I have a different control with a b...

ASP.Net MVC: Request variables through Routes and View method

Basically if I wanted to make something a search page with paging I would need a url like: /Topics/Index?search=hi&page=1 What I can't seem to figure out is how to: A) Set a default route with no search and page 1 /Topics/Index?page=1 or even /Topics/Index?search=&page=1 B) use the View method to do the same I do see that if ...

What should you be storing with an ASP.NET Profile Provider?

What is the role of the Profile Provider in ASP.NET / MVC? What kind of information should be stored/retrieved using this functionality? How does it fit in with the rest of the family of user providers: Profile Provider Membership Provider Role Provider ? ...

Generating JSON request manually, returned HTML causing issues.

Hi, I am generating my JSON manually, and I even escaped for quotes with a preceding backslash. It is causing me problems. My HTML returned looks something like: <div class="blah"><div class="a2">This is just a test! I hope this work's man!</div></div> string json = "MY HTML HERE"; json = json.Replace(@"""", @"\"""); Is there mo...

Is the [Authorize] attribute for ASP.NET MVC controllers only for Membership Providers?

Does the [Authorize] attribute used with ASP.NET MVC controllers only function with sites that have implemented a MembershipProvider? ...

ASP.net MVC DropDownList Pre-Selected item ignored

I am facing a simular problem as outlined in the question "Html.DropDownList in ASP.NET MVC RC (refresh) not pre-selecting item" I'm using ASP.net MVC 1.0 and need to associated a javascript call when the DropDownList is changed. <%=Html.DropDownList("SelectList", (SelectList)ViewData["SelectList"], ...

How to get the current route ID within a View from the URL (ASP.NET MVC)

Within the view that is returned from a URL such as /Controller/Action/1 (assuming the default route of controller/action/id), how can I get access to the ID from within the View? I don't want to have to add it to the ViewData dictionary at the action level when handling the request. ...

Should I be able to understand this ContentPlaceHolder behavior?

Hi, My goal is to be able to define a class for the element in a child page. On my master page I have the following: <body class="<myown:AttributePlaceHolder runat="server" ID="BodyCssClass"/>"> The AttributePlaceHolder derives from ContentPlaceHolder, and just strips out any linebreaks and extra spaces from its content. The problem...

Is there any benefit to using single Repository instance for Asp.net Mvc application?

In CarTrackr project, It use some technique that creates only 1 repository instance for all request in Asp.net Mvc website and uses UnityControllerFactory class to manage all repository instanes(send to requested controller). Is there any benefit to using single repository instance when compare with creating new repository instance eve...

mvc partial post back when button is clicked using ajax

Scenario: I am having a dropdown, a button and html table which displays data from the Model. Below is the code in aspx & controller Data is displayed without a postback when i click the submit button, but dropdownlist & button appears twice and then the following clicks are fine. Should i be using Html.RenderPartial anywhere, not sure...

Which language is used when mapping parameters to model?

I posted a decimal formvalue in InvariantCulture (16.4) and was surprised that it didnt get to the Model on my german system. I had to use the german format (16,4). Is there a way to configure the language that is used for parsing parameters? EDIT: After debugging into the sourcecode found the language specific parts in ValueProviderD...

Convert C# to VB.Net - Using MVCContrib Blockrenderer to render a partial view to a string

I need to render a partialview to a string, and I am trying to convert a C# example to VB.Net, as I am stuck with that for this project. This is causing me a headache from these two problems: ObjectViewData - I can't figure out what that is RenderPartial is a sub, but seems to be used as a function - I don' get it I reference the MV...

ASP.NET MVC 2.0 overview information?

I have heard that Microsoft is developing a MVC 2.0 platform for Visual Studio 2010. Does anyone have a good source of information about the upcoming project? Specifically, an overview of the changes and new features? ...

ASP .NET MVC: Html.Radiobutton onclick -- set ViewData[""]

Hi, I'm new to ASP .NET MVC and to web programming in general. I'm wondering if there is a way to set ViewData variables when a radiobutton is selected -- but before the page is submitted. Maybe I'm barking up the wrong tree but what I'm trying to do is create a form where new fields are added based on which radio button is selected. S...