asp.net-mvc

ASP.NET MVC AjaxHelpers recommended usage

It seems all the examples I come across specifiy an UpdateTargetId to render out the HTML content of the Ajax response. This is quite a bit different than how it's done in the Rails world, where the response content contains JavaScript code which manipulates the page. The Rails convention seems more powerful. What's the recommended usag...

Who has the responsibilty of loading data?

In the MVC model, where does the responsibility of loading the view model lie? Should the Controller load the data? Should the View Model itself load the data ala: MyViewModel viewModel = MyViewModel.Create(someValue); Should a Service Layer load it ala: MyViewModel viewModel = MembershipService.Instance.Load(someValue); ...

Anonymous type as object, how can I access a property?

I am adding some functionality to the HtmlHelper-class. Basically I want to automatically disable links on a web page based on user privileges e t c. So I have this function: public static string ActionLinkWithPrivileges(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues) { return LinkExtensi...

Retrive data from two tables in asp.net mvc using ADO.Net Entity Framework

Please read my question carefully and reply me. I have two tables as table1 and table2. In table1 i have columns as AddressID(Primary Key),Address1,Address2,City In table2 i have columns as ContactID(Primary Key),AddressID(Foriegn Key),Last Name,First Name. By using join operation i can retrive data from both the tables. I created a...

DotNetOpenId - Open Id get some data

I'm using OpenId on a new website and am trying to get some basic information about the user, see the code below. Why is the following allways null? var myData = response.GetExtension<ClaimsResponse>(); And the main code [System.Web.Mvc.AcceptVerbs(HttpVerbs.Get)] public ActionResult LogOn() { var openid = new OpenIdR...

Unregistered users in database

I'm creating a discussion forum (of sorts) in ASP.NET MVC, and I have a requirement to allow posts by unregistered visitors. Visitors only need to specify an alias to post, and can optionally provide an e-mail address and a website url. What's the best practice in handling posts by unregistered users in a database? I'm a bit of a newb...

What's the best method to be overloaded in ViewPage for inserting some script to all ViewPage?

I want to insert some script that is required for my JavaScript library in all view pages. I know that Asp.net MVC is built on Asp.net Framework. Therefore, I can override many methods in “System.Web.UI.Page” class that is a parent of “System.Web.Mvc.ViewPage” class. Nevertheless, I can do it by override Render method but it makes all ...

How to get Model errors in AjaxSubmit?

I am using AjaxSubmit to post a form and there are server side validations done using XVal (RuleException way). I am not using the try/catch way to add error to Model and then send to view. Instead - I want to use the HandleError attibute and in the OnException I am adding the errors to Model. The major problem is how do I get those erro...

how to perform online editing of an asp.net mvc site like sharepoint site

Hi al, i have a requirement in which i need to edit a live asp.net mvc site, same like a sharepoint site. In sharepoint i have an edit option where the content will be displayed in HTML Form, where i can change the content and save it. In same manner i need to do it on an asp.net mvc site. is there any option accross to do this? ...

Can I Use ASP MVC inside an ASP.Net WebForms Applications (Using 2 different programming languages!)

We'd like to use the ASP.Net MVC Framework to extend (and gradually convert) an existing ASP.Net Webforms application which we've "inherited". I know that we can add MVC into a Webforms project, but the existing project is written in VB.Net and we would much prefer to use C# going forward. Our ideal solution is to be able to add Contro...

Using ASP.NET MVC v2 EditorFor and DisplayFor with IEnumerable<T> Generic types

I have a IList<Tag> as a property named Tags in my model. How do I name the files for display and editor templates to respect it when I call DisplayFor or EditorFor? Usage: Model class MyModel { IList<Tag> Tags { get; protected set; } } View <%= Html.EditorFor(t => t.Tags) %> edit I know I can do this, but its not what I wan...

How to access .net MVC ViewData from Jquery directly

I am passing viewdata into my aspx page like so: //Controller List<user> userList = Data.GetAllUsersForCompany(companyId); List<SelectListItem> dropDownList = FormatUserList(userList); ViewData["UserList"] = userList; ViewData["FormattedUserList"] = dropDownList; return View(); I am populating a drop down with the name of a user, whic...

Can I expand/collapse a table in MVC?

I have a table and would like to give an option of whether you want to expand or collapse. If possible, I would also like to show the first 5 recods in the table. I can make two separate tables and toggle, yes, but is there a more efficient way? ...

passing css class name to asp.mvc view helper

In ASP.NET MVC view helper, you can do something like <%= Html.ActionLink("click me", "DoSomething", null, new { someAttribute = "a value" } ) %> which will produce the following HTML <a href="DoSomething" someAttribute="a value">click me</a> My question is.... what if I want to set the "class" attribute? <%= Html.ActionLink("cl...

Saving contents of ApplicationState in ASP.Net (MVC)

I have an internal app used to edit XML files on disk. The XML files are loaded into an object model which is stored in ApplicationState. I need to save this data. The one option is to do this every time the user changes some data. However, this seems a bit inefficient - writing the data out to disk each time a change is made. Instead,...

ASP.NET MVC Project Structure for larger sites

I'm surprised I can't find more discussions out there about an issue that is really bothering me on our project using ASP.NET MVC. How can you deal with a Visual Studio solution that has multiple projects? The MVC framework has the Models/Views/Controllers folder in the main project. But what if you want to break up your solution into ...

Deploying ASP.NET MVC 2 Preview 2 with Areas

We migrated from MVC 2 Preview 1 to MVC 2 Preview 2 to using multi-project areas. Everything works perfectly on local dev machine (Visual Studio 2008 SP1/IIS 7), however, it's does not work after I publish it to the server (Windows Server 2003/IIS 6). The deployment is done through the Build->Publish option in the VS2008 menu. I had als...

How to build a multi-view portal application in ASP.NET MVC

I was just watching Scott Hanselman's presentation on ASP.NET MVC in San Francisco. After thinking about it for a while, I was stumped as to how to best approach building an ASP.NET MVC-based site that has a [portal|modular|multi-view] structure (pick your favorite definition). To give you an idea of what I'm after, my company builds a ...

asp.net MVC partial with dynamic inherits class?

Hey guys, I have a partial view that is shared between two controllers and I'm trying to find a way to change what it inherits from depending on which view it is being called from or which controller. IE: my current partial is started like so: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MVCProject.Controllers.P...

Should a service be given a reference to another, or should the caller gain extra responsibility?

There are two classes in my project (using ASP.NET MVC): AuthenticationService, and ProfileService. When a new user registers at my site the Authentication controller's Register action calls a Register method in IAuthenticationService, which creates an authentication record for the user according to whichever concrete authentication modu...