asp.net-mvc

Crete a Shared View using a Model method

I want to create a shared control where i want to generate markup according to the role of logged in user. TO achieve this I need to call a method in Model class. Is this a right way to do this in ASP.NET MVC as I heard that we should strictly separate out Model and Views. Please help. ...

Avoiding spaghetti code in ASP.NET MVC

Probably a stupid question, but here goes. In my view, I have the following code.... <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Learner.MvcApplication.ViewModels.PagerViewModel>" %><% for (int i = Model.StartPage; i <= Model.EndPage; i++) { %> <% =Html.Label(ViewData.Model.Controller + i.ToString())...

ASP.NET MVC: is it a good idea to return a File result from a byte[] ?

I have an action in one of my controllers which creates a downloadable zip file which should be served to the user. Currently my code looks something like this: using(var memoryStream = new MemoryStream()) { // ... use SharpZipLib to write zip file content to the above MemoryStream ... return File(memoryStream.ToArray(), "applic...

Fire JavaScript from a Controller method

I'm working with a fairly common pattern - a page opens a child window (a popup) where a form permits the user to edit information (create new User Account). The controller validates the popup's submission and either tosses error messages or commits the update. If the update _is committed the user has no further need for the popup. I ne...

MVC - Ajax.BeginForm gives htmlfile: Unknown runtime error

I am trying to implement an Ajax.Beginform on my page but when I try to run the code, on postback I get the following alert htmlfile: Unknown runtime error I've tried trawling the web for a solution but no joy so far. Seems the problem is caused uite often by having multiple forms on the page but the Ajax form is the only one I ha...

Displaying user website link in view

Is this fine or is there a different way? <a href="Http://&lt;%=Html.Encode(Model.Website)%&gt;"&gt;&lt;%=Html.Encode(Model.Website??"")%&gt;&lt;/a&gt; ...

Getting at ViewData.Model from spark template post

I am trying to convert my spark views to use ViewData.Model instead of the namevaluecollection so that I can use AutoMapper to map my dto's to entities before it gets into my action method. I can access the viewdata.model from the view, but upon posting back the data, viewdata.model is null. here is some sample code: in my view: <view...

ASP.NET MVC on 2008 R2 IIS7.5 Not Loading

as the title notes, we can't get in to our site. this same site works fine for us in 2003 and in our dev environments. but once we moved to 2008 R2: we "can't get in". i'd love it if we could use fuslogvw to watch the assembly bindings: but that's not possible on these servers (no sdk installed). i've seen other posts that say nothin...

Authorization and Windsor

I'm trying to implement my custom authorize attribute like: public class MyCustomAuth : AuthorizeAttribute { private readonly IUserService _userService; public MyCustomAuth(IUserService userService) { _userService= userService; } ... continued } I am using Castle Windsor for automatically resolve the depende...

Hybrid area organization in Asp.MVC preview 2

Hi, I´d like to know if it is possible to create an hybrid solution using areas in mvc. I have a project with several areas within the same project and I would like to add a new area but in a separate project. For the moment I cannot achieve this, I think I have configured everything as it is stated in the walkthroughs. Has anybody been ...

ASP.NET MVC Forum Application

I need to write a forum application for a friend's web site. I want to write it in C# 3.0 against the ASP.NET MVC framework, with SQL Server database. So, I've two questions: Should I use Linq to SQL or the Entity Framework as a database abstraction? Should I use the ASP.NET Membership API or add Users table and implement it myself? ...

Unit test a controller with custom model binder

In my application I have a custom model binder that I set to the DefaultBinder in the global.asax: ModelBinders.Binders.DefaultBinder = new XLDataAnnotationsModelBinder(); When writing unit tests for controllers I need to make sure the controller uses the custom model binder but I don't know how to do this. My test looks like this: ...

APS.NET MVC newbie: getting/passing data in dropdown form for multiple objects in an edit View

Using the Authors/Books catalog example... Let's say I want to edit the info for the books of a specific author. When someone navigates to domain.com/Books/Edit/2, I want to display an edit view for all the books where Author_ID = 2. Among the various book info is the book category (fiction, non-fiction, textbook, whatever) These cat...

How can I force re-authentification on asp net mvc with Integrated auth

My MVC site is using integrated authentication, and we had a request to allow users to sing in as another user, like in sharepoint. This has proved to be difficult... I've tried to send a 401 or 403 response, but the browser won't display the login popup and the user will continue to be loged in. (Fidler and firebug tell me that the res...

Default page is not working

ASP MVC 1.0 being hosted on IIS 6. I set up the wildcard filtering already. When the user visits the root of the site, the home view appears but the jquery is non functional when trying to ajax query Home/SummaryView If I browse to the actual view url /Home then every thing works. Works fine in VS with the ASP .Net dev server. ...

Master Site links not working under iis6

ASP MVC 1.0 being hosted on IIS 6. I set up the wildcard filtering already. The path ../../site.css and the like in the master page (shared/site.master) do not work when posted to the IIS 6 staging site. I ended up hard coding them to the site. Works fine on the ASP .Net VS dev server ...

Install MVC on 2.0.NET Server with IIS6 without Admin Rights

On my local machine using IIS 5 (winxp) and visual Web Developer, I've built a beautiful and well composed website using MVC. Now to deploy to the testing server. I find out that it does not have MVC installed - Error:- Parser Error Message: Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyTo...

Asp.NET MVC Customer Application

I'm designing (and developing) web software that will allow the general public to sign up for a service, become a customer, and exchange fairly sensitive data. I'm working through the documentation and the tutorials, and of course the RESTful pattern adopted by the default routing in ASP.NET MVC is to do URL's like this: /customer/edit...

What is a quick way I can add simple authentication to a few ASP.NET MVC routes, without implementing the whole Membership provider jazz?

I've created a demo website for my boss and one of the requirements is I need to add some simple authentication to his 3 admin views/routes. What is the simplest, quickest way I can do this without implementing a whole membership provider? I honestly don't even care if the user/pass is hardcoded on the server side, I just need it so th...

Encapsulating User Controls in ASP.NET MVC

Sorry if this is a basic question - I'm having some trouble making the mental transition to ASP.NET MVC from the page framework. In the page framework, I often use ASCX files to create small, encapsulated chunks of functionality which get inclded in various places throughout a site. If I'm building a page and I need one of these contro...