asp.net-mvc

Combine an 'in-line IF' (C#) with response.write

in a conventional C# code block: "myInt = (<condition> ? <true value> : <false value>)" but what about use inside an .aspx where I want to response.write conditionally: <% ( Discount > 0 ? Response.Write( "$" + Html.Encode(discountDto.Discount.FlatOff.ToString("#,###."): "")%> mny thx ...

ASP.NET MVC: Binding to multiple models

I'm playing with an ASP.NET MVC application and I've run into a bit of a problem. I am pretty new to ASP.NET MVC and just barely understand the basics to get things to work at this point. I have a PersonModel, a PersonController, and a bunch of views that let a user add a new person, edit a person and search for people. I am not using ...

Execute Code on Every Request

I want to be able to execute some code on every request that stuffs data into ViewData. Currently I have a base controller class that all my controllers inherit from and I override OnActionExecuting and do it there. My only concern with this approach is that whom ever creates a new controller will HAVE to inherit form the base class. I...

Aggregating within the foreach loop

I have a loop: <% foreach (User usedBy in discountDto.UsedBy) { %> <%=usedBy.FullName%><br /> <% } %> that often produces multiple lines with the same name: Bob Smith Mark Thomas Mark Thomas Steve Jones I would like to aggregate the multiple lines to a single line followed by an integer representing the number of times that...

asp.net mvc and linq to entities: how to test model custom binding?

I'm trying to build a test for my custom model binder, but not having any success. The call to base.BindModel always returns a null. Is there a way to test custom binding when using LINQ to Entities? foo in this case is a table in the db with two fields - a numeric and a text value. fooBinder.cs: public override Object BindModel(Con...

ASP.NET MVC - Form Returns Null Model Unless Model is Wrapped in a Custom ViewModel

I have a pair of views in my application that both display the same Editor Template for one of my model items; of the two views ("Add" and "Edit"), "Edit" works fine, but "Add" is returning null for the model when my controller action handles the post. I found that if I give the "Add" view a custom ViewModel and call Html.EditorFor(p =>...

Where to store logged user information on ASP.NET MVC using Forms Authentication?

Hello mates, I'm using ASP.NET MVC and Forms Authentication on my application. Basically I use FormsAuthentication.SetAuthCookie to login and FormsAuthentication.SignOut to logout. In the HttpContext.Current.User.Identity I have stored the user name but I need more info about the logged user. I don't want to store my entire User obj in...

How many workflow runtimes should there be running for in an Asp.Net application?

Hello Gurus, There doesn't seem to be many Windows Workflow Foundation gurus out there :( Here are couple of challenges that I face: How many workflow runtimes should there be running for in an Asp.Net MVC application? One per application, per session or per request? How frequently should the workflow runtime be started and stopped...

What HTML helper do I use to create a simple dropdownlist that doesn't take in any variables?

I want to have a simple select->option dropdown list that I am not passing any (SelectItem collection) values to. I already know the values so I don't need to do all that (they are static). Need to do something like so: <select id="day" name="day"> <option value="1">Sunday</option> <option value="2">Monday</option> </select> <sel...

Dynamic subdomains in asp.net mvc

I am fairly new to asp.net, and have little experience with iis. I would like to have each user of my application get their own sub-domain, but all use the same controllers. The subdomain would then control what content is displayed. Example: user1subdomain.mydomain.com/Whatever user2subdomain.mydomain.com/Whatever Will both use the ...

ASP.NET MVC Simple validation of my form fails

Hi, I have a simple for with at text field where the user enters the address of a RSS feed. I wont act if the field is blank, this is my markup: <%=Html.ValidationSummary() %> <table> <tr> <td> Feed Url: </td> <td> <%=Html.TextBox("url", null, new {@style="w...

ASP.NET MVC : How does my action result find the selected entry in a dropdownlist?

I have a dropdownlist that I populate with some stuff: In my controller ViewData["SourceModelList"] = new SelectList(_modelService.GetAllModels(), "Id", "Description"); in my view <% using (Html.BeginForm("Compare", "Home")) { %> <p> <%=Html.DropDownList("SourceModelList")%> </p> <p> <input t...

Multiple Forms with Submit enabled via Checkbox

First, housekeeping: A quick review makes me think this isn't a duplicate but would be happy to be corrected. I've got an ASP.NET MVC app that have a page with multiple forms, each form has some text fields, an agreement checkbox and a submit button. I'd like to disable the submit button if the agreement checkbox isn't checked individua...

How can I create a templated control with Asp.Net MVC?

I'm trying to create a templated control with Asp.Net MVC. By templated control, I mean a control that accepts markup as input like so: <% Html.PanelWithHeader() .HeaderTitle("My Header") .Content(() => { %> <!-- ul used for no particular reason --> <ul> <li>A sample</li> <li>A second item...

xVal and jQuery Submit Button

I have a simple form. Its got one field and a submit button. I hide the submit button. The submit button is actually triggered with an anchor tag that calls a javascript method that uses jQuery to get the element and execute a click(). This works fine, the form posts and record is successfully written into the DB. So now I added xVal fo...

jquery load returns empty, possible MVC 2 problem?

I have a site that need to get some data from a different sit that is using asp.net MVC/ The data to get loaded is from these pages: http://charity.hondaclassic.com/home/totaldonations http://charity.hondaclassic.com/Home/CharityList This should be a no brainer but for some reason I get an empty response, here is my JS: <script> ...

MVC - How to store/assign roles of authenticated users

I am upgrading a site to use MVC and am looking for the best way to setup Authenication. At this point i have the login working off of Active Directory, validating a username and password and then setting the auth cookie. My question is how do i store the users role information at time of login in order for my controllers to see those ...

Log User Activity on ASP.NET MVC Application

Is there A good strategy to Log the User activity on an ASP MVC App? (ActionFilters/ HTTPModules). Something like last user activity (just like StackOverflow "Seen 23 mins ago"), and even what Pages and Controllers were used, and pushing even further what buttons or links were clicked. I have ELMAH installed but as far as i know its j...

MVC Updatemodel and Linq-To-Sql creates new entity instead of updating

Hi, I have a survey form with the following data hierarchy survey -< surveyQuestions -< surveyQuestionOptions I use updateModel to update the Survey entity in my save method which works fine for survey and surveyQuestions, however surveyQuestionOptions appear updated when I examine the updateSurvey variable in debugger but after I cal...

Intermittent PolicyException: Execution permission cannot be acquired.

We are intermittently seeing the following exception shortly after an App Pool recycle in an ASP.NET application: System.Configuration.ConfigurationErrorsException: Could not load file or assembly 'Microsoft.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant permission to execute....