asp.net-mvc

asp.net mvc database interaction validation

Does anybody have any links or advice on how to hook up validation that requires interacting with the database before updating or adding to the database? Every example I see shows how to validate properties e.g. "Is Required", "Is Email", "Is Numeric", etc, but how do you hook up validation for "Can't order out of stock item"? This xVal ...

performance problem after adding machinekey in web.config

Does adding a machinekey in the system.web of your web.config cause any performance problems? I added something like this to my web.config: <system.web> <machineKey validationKey="aaa" decryptionKey="bbb" validation="SHA1" /> </system.web> and now it seems to run quite a bit slower. I am using firebug to see how fast the page is lo...

Trouble print meta tags with ASP.NET MVC

I'm trying to make a meta tag in my view based on data in my model...my view code looks like this: <meta name="description" content="<%=Html.Encode(Model.MetaDescription) %>" /> But my output looks like this: meta name="description" content="&lt;%=Html.Encode(Model.MetaDescription) %>" /> What the heck am I doing wrong? ...

Determine if app is running in azure or not.

I have an asp.net mvc app that is built to run as standard web app in iis or in the cloud. I need to be able to determine if the app is being hosted in azure(dev fabric or cloud) or if it is being run as standard web app under iis. How can I tell if it is running in cloud? ...

There is no ViewData item with the key 'Blah' of type 'IEnumerable<SelectListItem>'.

This error message is driving me nuts. I'm getting it when using Html.ListBox and Html.DropDownList HtmlHelpers with ASP.NET MVC v1.0. Populating the lists works OK - I can view them, etc - but when I go to create a new record in the Model using the FormCollection passed into the Controller to get the selected value, this error occurs. ...

How do I make Ajax.ActionLink update an element instead of navigating the whole page?

I am trying to update a <div> in my view when the user clicks on an Ajax.ActionLink. However, it always navigates the entire page rather than inserting the server's response into the element I specify. I feel like I'm doing everything in this example, but even after creating the simplest test case I still can't create the behavior I wa...

Update Two DIV's on AJAX success - Combine JavaScriptResult & PartialViewResult?

At the moment I have a jQuery do a POST to a Controller which returns a ContentResult. When the OnSuccess event fires from jQuery it updates a div with the returned data. I now want to update another DIV with model data. I am thinking have a RenderPartial in my view, do the post and return a PartialResult which will handle this new di...

How do I get the user (IPrincipal) from a partial view in ASP.NET MVC?

On a System.Web.UI.Page.ViewPage I have access to the current User (System.Security.Principal.IPrincipal) but I don't have access to the User through a System.Web.UI.UserControl.ViewUserControl (the ViewPage property is internal). How can my partial view (.ascx) display information depending on who the IPrincipal is? ...

Controlling Controller Action call order

Hi, I'm knocking together a wizard like web app that will take input in a form and conditionally redirect to a confirmation page if the item entered already exists. Something along the lines of "there is already a product in the system with that name are you sure you wish to continue?". I can have an action "Confirm" on my controller...

ASP.NET MVC List All Users

I'm trying to show a list of all users but am unsure how to go about this using the MVC model. I can obtain the list of all users via the Membership.GetAllUsers() method however if I try to pass this to the view from the ActionResult, I'm told that Model is not enumerable. Thanks for any advice on this one. ...

ASP.Net MVC & Memberships...

Hi all, I would really appreciate some feedback on what I am trying to achieve: The problem: I would like to authorize a user of my application to a single action on the controller. For e.g.: a user can perform the "save" action on my controller class if he has the required authorization. In the project I am working on, the creation ...

Is it a good practice to define which data to load in the controller?

Imagine you have an entity that has some relations with other entities and you want to load only some of these entities to display them in diferent views. For example, given this entity: public class Category { public int id; public Category child; public Category parent; } In the view "ShowChild" you don't want to lo...

Generic partial view: how to set a generic class as model?

I'm trying to build a generic grid view in an ASP.NET MVC application. Let me explain with some code: public interface ITrustGrid<T> { IPagedList<T> Elements { get; set; } IList<IColumn<T>> Columns { get; set; } IList<string> Headers { get; } } This is an interface of a class that allows me to set columns and expressions ...

ASP.net mvc Common data for footer

So, I have a footer which will appear on every page of my web application I need it to render dynamic data so.... this means that every controller action needs to return viewData which contains this data.. as well as the action specific data How would you guys implement this? The constructor of a base controller perhaps? ...

Linq2Sql Insert Records To Related Tables

Hi There, Similar situation to : http://stackoverflow.com/questions/630320/how-to-add-several-dependent-records-with-linq2sql (this seems logical, but it doesn't work for me) ASP.NET MVC + Linq2SQL I have 2 tables called Challenges and Participants. Challenge { challengeId, ChallengeDesc, applicantId, respondantId } Participants {...

ASP.Net VS ASP.Net MVC

Hello! Now this isn't a question as to which of the technologies is better, since they both have their relevant uses for different scenarios. My question is regarding the syntax of the two. How do their syntax's differ? ...

ASP.NET MVC: How to Deal with Null objects in View?

Should model objects that go to the view be checked for null before going to view? And if null, create a dummy instance? Or should the View check for null? ...

Image Editing using ASP.NET MVC

Is there any good image editing component for ASP.NET MVC? That can crop/re-size/rotate etc ...

Html Helper Extensions not being found

I'm using the release version of ASP.net MVC and I seem to be getting this error a lot 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderPartial' and no extension method 'RenderPartial' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly refer...

How to export data to pdf in asp.net MVC?

I don't have grid view as I am working on asp.net MVC. So can I create Response object which writes data into pdf format Response.AddHeader("Content-Disposition", "attachment; filename=data.pdf"); Response.ContentType = "application/.pdf"; I use these two lines but I don't know in which format, I should write data? ...