asp.net-mvc

Count selectlist items (count IEnumerable)

As you can see here and here I'm not a good friend of asp.net MVC's SelectList. This time I'm wondering how to count the items in it. I want to show a label instead of a dropdown if the possible items don't offer any choice (items.count <2). --EDIT-- Although Will's answer probably works too, the easy way to go is call .GetListItems...

Export to Excel in Asp.net MVC

I am working on an ASP.NET MVC application where I need to export data to an excel spreadsheet. Previously, in webforms apps, I used some code I found to render a GridView as an excel-compatible file. This was quite handy. I was wondering what the quickest/most effective method would be to do this in MVC. Thanks. ...

Why is this query string invalid?

In my asp.net mvc page I create a link that renders as followed: http://localhost:3035/Formula/OverView?colorId=349405&amp;paintCode=744&amp;name=BRILLANT%20SILVER&amp;formulaId=570230 According to the W3C validator, this is not correct and it errors after the first ampersand. It complains about the & not being encoded and the enti...

Strongly Typed Views in ASP MVC

I have been looking through Scott Guthrie's MVC tutorials and it seems like the syntax for doing strongly typed views has changed, or I am doing something wrong... My controller code: return View(CurrentUser); Code behind in the view: public partial class EditProfile : ViewPage<User> Yet in the view's front end code if I type...

An MVC Framework Comparison (primarily cost/speed tradeoffs)

I'm developing an idea for a web application that would be well suited to one of the popular MVC frameworks out there right now, but torn between which to go with. I was originally going to go with Pylons, but upon reading about the BizSpark program, I'm reconsidering ASP.NET MVC. The hitch is that if I'm successful I'll need to pony up...

Is there a way to send optional parameters to an action?

Can I send optional parameters (empty strings, null int?'s etc) to an action through a GET request in asp.net mvc? (one sentence question!) ...

How do I use ModalPopup from the ASP.NET Script-Only ajax control toolkit?

I am using the ASP.NET Client-Side ajax control toolkit in my asp.net MVC application. I see that there is a .js file named "AjaxControlToolkit.ModalPopup.ModalPopupBehavior.js" in the AjaxControlToolkit folder. However, I cannot find any examples on how to use it. [Edit] - As mentioned, I am using the Client-side, Script-only control to...

How to use Ajax.BeginForm MVC helper with JSON result?

I'm trying to use the ASP.NET MVC Ajax.BeginForm helper but don't want to use the existing content insertion options when the call completes. Instead, I want to use a custom JavaScript function as the callback. This works, but the result I want should be returned as JSON. Unfortunately, the framework just treats the data as a string. Be...

How to cleanly reuse edit / new views in Asp.NET MVC

I'm trying to avoid code like this when reusing the same ViewUserControl in ASP.NET MVC. Any suggestions? <% if (ViewContext.ViewData["editMode"].ToString() == "edit"){ %> <%= Html.SubmitButton("submit", "Update Brand")%><span class="or">Or</span><a href="#" class="cancel">Cancel</a> <% } else { %> <%= Html.SubmitButton("submit"...

Linq to SQL update not working using Repository pattern

I am using asp.net mvc for an application. I've taken some guidance from Rob Conery's series on the MVC storefront. I am using a very similar data access pattern to the one that he used in the storefront. However, I have added a small difference to the pattern. Each class I have created in my model has a property called IsNew. The i...

Html helper for <input type="file" />

Is there a HTMLHelper for file upload? Specifically, I am looking for a replace of <input type="file"/> using ASP.NET MVC HTMLHelper. Or, If I use using (Html.BeginForm()) What is the HTML control for the file upload? ...

Iterate through an anonymous variable in another scope then where it was created

I am writing an unit test for a mvc web application that checks if a returned list of anonymous variables(in a jsonresult) is correct. therefore i need to iterate through that list but i cannot seem to find a way to do so. so i have 2 methods 1) returns a json result . In that json result there is a property called data. that property ...

Html.DropDownList and modelbinding

Why isn't modelbinding working on a DropDown? What am I doing wrong? To illustrate my problem, I did the following: Created a new asp.net MVC project (beta1) Created the following class: HomeViewData : ViewDataDictionary +List : SelectList Added a viewdata to the HomeController class as following Homecontroller: Controller +HomeVi...

How do I imitate the ASP.NET AjaxOptions delegate functions?

When using the Ajax.BeginForm() helper in ASP.Net MVC, I can pass options with names of different functions, for example one to run OnBegin, one for OnSuccess etc. How do these work "under the hood"? The reason I'm asking is that I'm extending this to provide a jQuery based alternative, and I need to figure out how to get from having th...

Overriding System.Web.Mvc.ViewMasterPage, where to make call to grab from cache?

Hi, I need to grab a value from the HttpCOntext.Items request cache, where should I do this? Is there a particular event or contsructor I should override? ...

How do I render a ViewPage to a string?

I have tried to implement simple ViewPage caching with ASP.NET MVC, however I cannot get the page to render correctly into a custom HtmlTextWriter when it has a master page. I have tried overriding Render. If I simply call the base implementation, then everything renders correctly. If I render to my own writer and then write that string...

In MVC, when do you use <%= %> and <% %>?

Hi, In asp.net mvc, when do we use: <%= %> and <% %> Do we ever need to put a ; (colon) ? ...

RESTful 'miscellaneous' pages in an ASP.NET MVC site?

Hi folks, Imagine we were doing this StackOverflow site in ASP.NET MVC (funny that, 'cause it is...). We have to develop the views: About this site Faq Privacy policy 404 page Error page etc... Now, because we want to keep this RESTful because we're trying to grow our RESTafarian Geek-fro's, do we throw them into one controller .. c...

When and why should I consider asp.net MVC?

I've noticed a lot of talk about asp.net MVC lately, but I haven't come across a clear or compelling description of when, where or why I would want to use it over WebForms. Let's say I wanted to build a small web application that allows a person to advertise some items online. The website will have 4 use cases: Search adverts View l...

Best quality/price shared Web Hosting for Asp.Net Mvc

I am having several problems deploying my Asp.Net MVC application with my current web hosting and I am thinking about trying a new one. What is in your opinion the one with best quality/price that allows to easily deploy ASP.Net MVC applications? Thanks! ...