asp.net-mvc

Do I need to fill ViewData (MVC 2) more than once?

I am following a simple ADO.NET Entity/MVC 2 tutorial wherein my Views are created by right-clicking the action and selecting 'Add View'. The views get created based on my model and all is good. I can view the initial list of items from the DB but when I click Edit or Delete or Details I get 'Object reference not set to an instance of an...

Separate functionality depending on Role in ASP.NET MVC

I'm looking for an elegant pattern to solve this problem: I have several user roles in my system, and for many of my controller actions, I need to deal with slightly different data. For example, take /Users/Edit/1 This allows a Moderator to edit a users email address, but Administrators to edit a user's email address and password. ...

ASP.NET MVC Dropdownlist retain the selected value in the browser after post

I build a drop down list in my aspx page as following <%= Html.DropDownList("SelectedRole", new SelectList((IEnumerable)Model.roles, "RoleId", "RoleName", Model.SelectedRole), "")%> it works fine for first Get and the first default value is selected; then I select item from the drop down list and submit the form. the controller bind ...

How to provide a fileDownloadName only if the user requests to save the file in ASP.NET MVC?

I've got a controller action that returns a FileResult like this return this.File("file.pdf", "application/pdf"); for the URL "/Download/322" - where 322 is the id of the file. This works great, so that if a user clicks on a link to the PDF - it will open in their web browser as long as they have a PDF plugin installed. But, what if...

ASP.Net MVC - Need to send other data along with Partial View

I need to send some other data, ideally wrapped in a JSON object, down to the client. As well as that however I need to send a Partial view. Now I can only think of two ways: Send JSON object and then make another call to load contents of partial view into div. Send HTML for Partial View as a property of the JSON object and then load i...

How to make one ASP.NET MVC site "derive" from another.

My question is similar to "ASP.NET 2 projects to share same files", but with an ASP.NET MVC slant. Basically, we have two sites, one being based mostly on the other (roughly 90% views, controllers, images, in the second are identical to the first). However, in some cases, the views may be different, or a controller in the second site ma...

Add property to an ASP.NET MVC 2 ViewUserControl

I have created a ViewUserControl in my ASP.NET MVC 2 project. This ViewUserControl serves as the general page-header for all views in the project. How can I add a custom property on ViewUserControls, accessible from views using that control?..: <%@ Register Src="../Shared/Header.ascx" TagName="Header" TagPrefix="uc" %> <uc...

Am I just not understanding TDD unit testing (Asp.Net MVC project)?

I am trying to figure out how to correctly and efficiently unit test my Asp.net MVC project. When I started on this project I bought the Pro ASP.Net MVC, and with that book I learned about TDD and unit testing. After seeing the examples, and the fact that I work as a software engineer in QA in my current company, I was amazed at how aw...

YUI Code Editor problem in Chrome, Firefox and IE (iframe, div tags)

I am using Yahoo Editor for my asp.net mvc (C#) application. When i tried to use the iframe, its ripping of the complete html. It works in Chrome, but not in Firefox and IE. I have tried pasting the below html in http://developer.yahoo.com/yui/examples/editor/code_editor.html. <iframe src="http://www.google.com" width="100%" height="3...

Input type button/submit that does both form validation and submit via jquery ajax?

I am trying to use jquery validator plugin and form submit via ajax in jquery..... Validator plugin works with <input type="submit" value="Add a client" id="clientadd"/> but my form submit works with <input type="button" value="Add a client" id="clientadd"/>..... <form id="addform" autocomplete="off"> //My controls here </form> I di...

How does an ASP.NET programmer go from working on/developing existing sites, to creating one from scratch?

I've been an ASP.NET developer for some time, always working on existing ASP.NET pages, modifying functionality, adding features, tweaking things etc. but have never built a site up from scratch. I've read books on ASP.NET, and they generally talk you through the various features of ASP.NET with a mock up site, but it's always very basic...

Facebook Graph API authentication in canvas app and track session

Short question is: how can i use graph api oauth redirects mechanism to authenticate user and save retrieved access_token and also use javascript SDK when needed (the problem is javascript SDK will have different access_token when initialized). I have initially setup my facebook iframe canvas app, with single sign on. This works well wi...

Maintain Constant Title Across Website

If I am creating a website in ASP.NET, is it possible to programmatically set the title of the page be some predefined value with some extra information tacked on? For example: Home Page Title = Site Name Links Title = Site Name: Links Stuff Title = Site Name: Stuff Basically, whatever I defined as the main title on ...

how to display using asp.net mvc

I have a partial view called StudentInfo.ascx. In it I have something like this: <fieldset> <legend>Students Information</legend> <div> <label>First Name:</label> <label>Last Name:</label> </div> </fieldset> I have another partial view called Detail.ascx which will need to display this StudentInfo.ascx. I did somethin...

In ASP.NET MVC, why wouldn't I tack on HandleError on a base controller and be done with it?

Since HandleError is inherited by the derived Controllers, why wouldn't I just create (or have) a base controller, and apply HandleError on it so that any controllers that inherits from the base controller will automatically be handled as well? And then I would tack on overriding HandleError on controllers and individual actions. Can a...

Sharing sessions across applications using the ASP.NET Session State Service

I am trying to share sessions between two web applications, both hosted on the same server. One is a .net 2.0 web forms application the other is as .net 3.5 MVC2 application. Both apps have their session set up like this: <sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" /> In the webfo...

Display virtual keyword asp.net for password

Hi! I have a login page with an input of type "password" I would like to have a virtual keyboard to enter the password. I've searched and I found the jquery script for virtual keyboard. The code said to add this to my page $('input[type=password]').keyboard({ layout: "qwerty", customLayout: [["q w e r t y {bk...

asp.net mvc 2 multithread

I'm getting some weird behavior in asp.net MVC2 (at least it's not what I'm expecting). I have a controller httppost action that processes credit cards. I'm setting a session variable on the server to let me know if a user has attempted to process a card. I clear that session variable when I'm done. I am doing some very quick posts t...

Why should a web architecture be loosely coupled?

When I look at ASP.NET MVC projects I everytime see loose coupled architecture. For what do I need a loose coupling in a web architecture (if I do not make unit tests)? What are advantages and disadvantages of this? ...

On Redirect - Failed to generate a user instance of SQL Server...

Hello (this is a long post sorry), I am writing a application in ASP.NET MVC 2 and I have reached a point where I am receiving this error when I connect remotely to my Server. Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user ...