asp.net-mvc

Trouble passing complex data between view and controller in ASP.NET MVC

Here's a simplification of my real models in ASP.NET MVC, that I think will help focus in on the problem: Let's say I have these two domain objects: public class ObjectA { public ObjectB ObjectB; } public class ObjectB { } I also have a view that will allow me to create a new ObjectA and that includes selecting one ObjectB from ...

upload an image and get its bytes

I have such a form <form name="" method="post" action="Save" enctype="multipart/form-data"> <div id="dialog" title="Upload files"> <input type="file" id="Image" name="fileUpload" size="23"/> </div> <input type="submit" value="Create" /> </form> how sould i get the get the images bytes in ...

ASP.Net MVC HABTM Association

I must be missing something, when trying to define a HABTM association with 2 of my models. I have a "Product" table, and a "Category" table, and a "ProductsCategories" join table. In SQL Server, I am defining the Relationship between the tables on the join table. However, when I create the LINQ to SQL model "Product," I get "Product....

How do I use MicrosoftMvcValidation.js without having to include MicrosoftAjax.js ?

It looks like there's an issue in MVC 2 RC1 if you want to use jQuery.Validate but not the main Microsoft AJAX - which is 25kb even when gzipped. According to Phil Haack you're supposed to be able to just include these scripts: <script src="/Scripts/jquery-1.3.2.js" type="text/javascript"></script> <script src="/Scripts/jquery.va...

HTML.DropDownList does not respect pre-selected value.

Hello, I want to use Html.DropDownList(string name, IEnumerable SelectList, Object htmlAttributes) to render a select list with a preselected value for me. My select list is in the model object of my view, so I have been writting the following code: <%= Html.DropDownList("aName", mySelectList, new { }) %> Which will render the select...

Does it make sense to return PageList<T> from my Model if I'm not using LINQ's lazy loading?

I'm working on a messaging system for a site of mine written in ASP.NET MVC. Right now, I'm attempting to iron out Pagination for the Inbox/Sent views. I've stumbled onto Rob Connery's PagedList<T>, which seems like a nice solution to the problem. However, one difference between my use-case and Rob's however is that I don't return IQu...

ASP.NET MVC 2 problem with UpdateModel

I'm trying to use updatemodel(myItem, formcollection) with asp.net mvc 2 but it fails with the stack trace below. at System.Web.Mvc.FormCollection.GetValue(String name) at System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) at System.Web.Mvc.Controller.TryUpdateMo...

How can I write custom comparison (definition for binary operator Equal) for entityframework object to an int?

I'm getting this error: ex = {"The binary operator Equal is not defined for the types 'MySite.Domain.DomainModel.EntityFramework.NickName' and 'System.Int32'."} What I tried to do was do a select all where the NickNameId = someIntPassedIn... the problem is that the NickNameId is a foreign key, so when it compares the someIntPassedI...

Visual Studio 2008 hangs when running Azure projects

My ASP MVC Web project runs and debugs without any issues in VS2008SP1 (.NET 3.5 SP1). However when I run the Azure project that refers to the same Web project as a Web Role, although it runs without issues, I can't go back to Visual Studio when I'm done. It seems as if VS is waiting for a modal form to close (I get the "bing" sound in...

Passing complex object from view to controller/view in ASP.NET MVC

In my MVC application I have a problem with passing data from view to controller. I have fairly complex domain classes: public class TaskBase : PersistableObject { public virtual TaskCategory Category { get; set; } public virtual IList<TaskNote> Notes { get; set; } public virtual string TaskTitle { get; set; } public vir...

ASP.NET MVC Model confusion

Background I'm learning the ropes around how to use ASP.NET MVC properly, and ran into this issue with models: I have a model that describes a contact I can get that out of the form for creating a new contact, but say when we edit a form, I retrieve it from the repository, show the fields on the contact form and then get the contact ob...

File download in MVC application

How do I set it so that when a link is clicked in a view, it prompts the user to download a file. ...

make sure each controller method has a ValidateAntiForgeryToken attribute?

Is there any way to centralize enforcement that every action method must have a "ValidateAntiForgeryToken" attribute? I'm thinking it would have to be done by extending one the "routing" classes. Edit: Or maybe do some reflection at application startup? ...

Publish Web dialog for a standard VS Website Project?

Until I started building MVC sites, I always built WebForm web sites using Visual Studio Web Site projects (instead of Web Application projects). When I publish my MVC sites, I'm loving the Publish Web dialog that allows much more control over the deployment than I'm used to. This is the feature I've been looking for for 5 years! Web ...

Get permission from Authorize Attribute?

I've implemented my own Authorize attribute, and I notice that it queries to check permissions when I use [Authorize]. Is there any way I can get that permission and use it in the current controller that applies the Authorize attribute without having to rewrite and requery the code in the controller? ...

MVVM ViewModel vs. MVC ViewModel

ViewModel is a term that is used in both MVVM (Model-View-ViewModel) and the recommended implementation for ASP.NET MVC. Researching "ViewModel" can be confusing given that each pattern uses the same term. What are the main differences between the MVC ViewModel and MVVM ViewModel? For example, I believe the MVVM ViewModel is more rich...

Common Compile/Runtime Errors in ASP.NET MVC

What are some common errors that programmers face in ASP.NET MVC when compiling or running their application? Example The incoming request does not match any route Please include the solution with the error, or if there isn't one set solution, what developers should look for when encountering these errors. ...

MaintainScrollPositionOnPostback is not woring in ASP.NET MVC page

I have a mvc viewpage where I have detailed form for users to fill. In the form there are 2-3 dropdowns. On selection of option in those dropdown the page is posted back. Now during these postbacks i want to maintain the vertical scroll position for the page. To achieve this I used Page Language="C#" MasterPageFile="~/Views/Shared/Site....

Web application design

I have a project that I have recently started working on seriously but had a bit of a design discussion with a friend and I think he raised some interesting points. The project is designed to be highly scalable and easy to maintain the business objects completely independently. Ease of scalability has forced some of the design decisions...

mvc.net redirecting form get to 'nice' url best approach

I currently have a collection of routes like {controller}/{action}/{from}/{to}/{some}/{other}/{things} {controller}/{action}/{from}/{to}/{some}/{other} {controller}/{action}/{from}/{to} {controller}/{action} and views with forms with get actions to retrieve the results. But the get actions go to the default/last route with the parame...