asp.net-mvc-2

How to simply update entity in entity framework?

Hi! I'm writing a custom .NET MembershipProvider (not the built in one) and trying to update using Entity Framework. But of course i have no access to (Try)UpdateModel. How can i update it? Thanks in advance. ...

Problem with MvcSiteMapProvider and dynamicNodeProvider

Hi I have add the provider in my web config as below: <add name="MvcSiteMapProvider" type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider" siteMapFile="~/Sitemap/SiteMap.sitemap" securityTrimmingEnabled="true" enableLocalization="true" scanAssembliesForSit...

Setting properties of textbox and formatting it in MVC 2

I'm using MVC 2. I want to format the data that I display in my textbox when I edit a record. I display my textbox like this: <%: Html.TextBoxFor(m => m.AnnualIncome, new { @class = "textbox", maxlength = "50", size = "15" })%> How would I format this? I tried adding the String.Format from below but it does not work: <%: Html.Text...

ASP.NET MVC 2 - "The model of type 'XYZ' could not be updated" when using UpdateModel and LINQ to Entities (.NET 3.5)

I have a model set up using LINQ to Entities and have code working that adds to the database as expected. However, I can't get UpdateModel to work when I am using .NET 3.5. [HttpPost] public ActionResult Edit(Site.Models.XYZ xyz) { try { var original = db.XYZ.First(u => u.id == xyz.id); UpdateModel(original); ...

Dynamically Constructing Lists on Client-side on ASP.Net MVC2

Hi, I need to create a list of dynamically generated entries on the client as the user can control how many entries he needs pressing a + symbol. Functionality in some sense is similar to the "Google Finance Stock Screener" add criteria. In code I have a model that looks like this: public class Model { public List<string> DynamicLi...

Best MVC architecture for multiple different known browser targets?

We are building a closed system using ASP.NET MVC. There are multiple touchpoints in this demo system, but all will be running browsers. All will be showing basically the same data, but the targets differ in several ways: Screen size and orientation. We have some at full HD, and others at 800x480. Some are portrait and some are lan...

I want to configure NVelocity with MVC2, Please Help...

I want to configure NVelocity with MVC2, Please Help... ...

Mvc2 areas and session

Do Areas in Mvc2 have session isolation or do they share the same session as the rest of the application for the same user. ...

MVC2 Partial View, Search Control - Design / Implementation

I have a partial view that is a search textbox and button. I am trying to make it a partial view so that I can render it in several places. When the user clicks search I want it to redirect to /Home/Search which will show a list of items based on what was put into the search box. Is this the right approach or should I make the form ...

How can I change a route value then redirect to that route?

I have a UserAccountController that takes routes like this "/{username}/{action}". I'd like to create some functionality so that I can take a user to an account-specific page without knowing their username up front. I'd like to be able to use the URL "/your/{action}" which would catch the fact that "your" was sent as their username, get...

Output controller Dianostics.Trace statements to a view page?

In Web Forms we were able to see out N-Tier System.Diagnostics trace statements at the bottom of a page because they effectively executed within the page lifecycle. In Mvc, I can find these trace statements using trace.axd and randomly searching the index, but I would really like my trace statements that execute inside my controller act...

How to create a custom HandleErrorAttribute that is routed to somewhere other than /Error?

Is there a way to create a custom HandleErrorAttribute that instead of routing users to "Error" instead routes them to something like "Error/Unknown" (where "Error" represents an Error Controller and "Unknown" an action method in it)? Thanks ...

Aliasing Querystring Params in BeginForm with FormMethod.Get - MVC2

The Question Is there a way to alias the parameters generated by MVC, in my case it would be the searchTerm param? For example, in my viewmodel it would still be SearchViewModel.searchTerm but the URL would look more like /Home/Search?s=jimmy Search Form <% using (Html.BeginForm("Search", "Home", FormMethod.Get)) {%> <%: Html....

Ajax.BeginForm Bug in MVC2?? Ajax for Posting to Wrong Controller?

I am using an ajax form trying to post back the the CustomerController using the Create method. Here is the code <% using (Ajax.BeginForm("Create", "Customer", new AjaxOptions { LoadingElementId = "saving"}, new { @class = "block_content form" })) {%>... When my html form renders the form looks like this <form onsubmit="Sys....

ASP.NET MVC2 inline code in view - mixing tags

I've run into a couple different exceptions with this block of code in one of my views: <% if (Model.Book.ReviewReference == null) {%> <%=Html.ActionLink("Rate / review this book", "Create", "Review", null, new { id = "reviewLink" }) %> <% Html.RenderPartial("CreateReview"); } else {%> <%= Html.ActionLin...

Can't get MONO_ASPNET_NODELETE to work

I'm trying to get to the temporary files that mono compiler is generating for my codebehind classes. But it deletes them after compilation is performed, while throwing errors to the console. Error messages reference files that are no longer available. In theory the MONO_ASPNET_NODELETE environment variable should prevent those from bein...

Purpose of ModelState.AddModelError with exception parameter

Is there a use for the overload of AddModelError() that takes an Exception as a parameter? If I include the following code in my controller: ModelState.AddModelError( "", new Exception("blah blah blah") ); ModelState.AddModelError( "", "Something has went wrong" ); if (!ModelState.IsValid) return View( model ); And the following...

Entity Framework Generic Repository Context

I am building an ASP.NET 4.0 MVC 2 app with a generic repository based on this blog post. I'm not sure how to deal with the lifetime of ObjectContext -- here is a typical method from my repository class: public T GetSingle<T>(Func<T, bool> predicate) where T : class { using (MyDbEntities dbEntities = new MyDbEntities()) { ...

Best way to handle IEnumerable properties in ASP.Net MVC2 Scaffolds

I have an object that has 2 properties which are IEnumerables of a complex object (file upload, caption, url) and of a string. I am wondering how to best handle this in scaffolding. Or is it something that should be done completely custom. This is a small budget website, so the simpler the better. ...

How to display selected value in the Dropdown list box

I have this code in my view. I need to display the selected value that is comming from the database in the Dropdownlist. <select id="PeopleClass" name="PeopleClass"> <option value="1">Name1</option> <option value="2">Name2</option> <option value="3">Name3</option> </select> Now I am getting default as Name1 but what ever t...