asp.net-mvc,asp.net-mvc-3,razorRelated issues-Collection of common programming errors


  • Noel
    c# asp.net-mvc asp.net-mvc-4 asp.net-web-api asp.net-web-api-routing
    I created a new ASP.NET MVC4 Web Api Project. In addition to the default ValuesController, I added another controller, ScenarioController. It has the exact same methods as ValuesController. But for some reason, it behaves differently./api/values/ => “value1″,”value2” /api/values/1 => “value” /api/scenario/ => “value1″,”value2” /api/scenario/1 => “value1”,”value2″^^^^^^^^^^^^^^^^^should return “value”!Using breakpoints, I know that /api/scenario/1 actually gets sent to the public IEnu

  • Muaz Khan
    asp.net-mvc
    I’ve got an unexpected situation when using Remote Attribute in ASP.NET MVC3. The model type I used:using System; using System.Web.Mvc; using System.ComponentModel.DataAnnotations;namespace dTweets.Models {// at first time, user should create his account with unique username// as in twitter.com, user dopublic class UserMetadata{[HiddenInput]internal int Identity { get; set; }[Remote(“IsUserExist”, “Account”)] // at any HttpPost, username should// be unique – not appropriate if // updating/editin

  • Rudi Visser
    asp.net asp.net-mvc asp.net-mvc-2 asp.net-mvc-4
    In ASP.NET MVC 2, the lifespan of an entry in the TempDataDictionary was just one HTTP Request.That translated to setting a value in one request, redirecting, and having access to the same item at the other end of the line. After this the entry would be no longer available, regardless of whether you read the value out of the dictionary at the latter end of the line or not.Since ASP.NET MVC 3 (I believe), this implementation detail has changed quite significantly.Entries in the TempDataDictionary

  • Martin Devillers
    c# .net asp.net-mvc asp.net-web-api asp.net-mvc-areas
    I am currently working on a ASP.NET MVC 4 Web Application project that must adhere to the following design decisions:The main MVC application resides in the root of the solution. All administrator functionality resides in a separate area. Each external party (e.g. suppliers) has its own area. Each area, including the root, constitutes a well separated functional block. Functionality from one area may not be exposed to another area. This is to prevent unauthorized access of data. Each area, inclu

  • abatishchev
    c# ajax asp.net-mvc http-post
    This behavior is making me wonder about my sanity..I have a form that has two places that accept input, let’s call them ValueA and ValueB. The user can enter a value in either one and the form submits.<div id=”MyUpdateTarget”><% using (Ajax.BeginForm(“MyControllerAction”, new AjaxOptions { UpdateTargetId = “MyUpdateTarget” })) { %><%=Html.TextBox(“ValueA”, Model.ValueA, new Dictionary<string, object> {{ “onchange”, “$(‘#SubmitButton’).click(); return false;” },}) %><%=

  • bigmac
    asp.net-mvc log4net ninject
    I am trying to properly use Ninject to inject log4net logging into my MVC3 application. I am using the Ninject.MVC3 package, so I have the NinjectMVC3 class that automatically extends the App_Start method and contains the RegisterServices method that binds all dependencies. I also have the Ninject.Extensions.Logging.Log4Net package, but I don’t know how to use it. I already know how to configure log4net in my web.config, but don’t know how to use this extension for DI.I have read all the foll

  • Carl Manaster
    asp.net-mvc unit-testing tdd
    So I want to learn a little bit of TDD and wanted to see if I could test an Index action which should simply return a View.The test doesn’t pass and the error isTest methodSummumnet.Tests.Controllers.PhysicalTestsControllerTest.IndexShouldReturnViewthrew exception: System.ArgumentException: Expression is not aproperty access: c => c.FindById(1)Here’s my controller action code:[Authorize][AllowedToEditEHR]public class PhysicalTestsController : Controller{private IUnitOfWork unitOfWork;private IR

  • Runscope API Tools
    asp.net-mvc linq-to-sql
    This is a little out there but I have a customer object coming back to my controller. I want to just reconnect this object back to the database, is it even possible? I know there is a datacontext.customers.insertonsubmit(customer), but is there the equivalent datacontext.customers.updateonsubmit(customer)???

  • TomHastjarjanto
    c# .net asp.net-mvc
    My question actually consists of multiple questions. I’m frequently reading about companies who deploy a small subset of features for a select amount of customers using the live “database”. Ruby on Rails and its ecosystem have deployment tools and database migrations to deploy or rollback such features in a live production or staging environment.My question, how is this done for an asp.net (mvc in particular) application? How do you test your newly released features against live data? Do you hav

  • SamWM
    asp.net-mvc subsonic t4
    In Visual Web Developer Express 2008 the SubSonic ASP.NET MVC template doesn’t seem to work with a new database I added. I removed the Chinook Database and created my own one. I understand the the .tt files in the Models folder are used to generate code, but they don’t (despite changing the ConnectionStringName to what I set in the web.config)Right clicking on each .tt file and selecting ‘Run Custom Tool’ does not generate anything, except an error message:Cannot find custom tool ‘TextTemplating

  • EH_warch
    asp.net-mvc-3 sql-server-express asp.net-mvc-scaffolding
    I’m creating a new MVC 3 pilot application using Mvc3 and the MvcScaffolding NuGet, everything runs smoothly until i want to use the database i already have. The application keeps creating a database with the format:projectname.Models.projectnameContextI’m stuck in here, my connectionStrings is:<connectionStrings><add name=”ApplicationServices” connectionString=”data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true” providerNam

  • Christofer Eliasson
    c# asp.net-mvc-3 version-control entity-framework-4.3 ef-migrations
    I have an ASP.NET MVC3 project that uses Entity Framework 4.3 with the code-first approach. I use Migrations to keep the database up-to-date.The project is under source-control and I have a number of branches. What I just realized is that there will be a problem when I wan’t to merge one of my branches into the master. Since I have created migration-files in both branches, there will be overlapping migrations when I merge, which will probably cause conflicts.Is there a good way to manage Migrat

  • Colin Desmond
    asp.net-mvc-3 entity-framework-4 optimistic-concurrency
    We have an ASP.Net MVC application that uses EF4 as its data access layer and we’re seeing unexpected behaviour with regards to OptimisitcConcurrencyExceptions not being thrown when we think they should be.We have simplified the problem down to the following code…using System.Linq;using Project.Model;namespace OptimisticConcurrency{class Program{static void Main(){Contact firstContact = null;using (var firstEntities = new ProjectEntities()){firstContact = (from c in firstEntities.Contacts wher

  • jwize
    asp.net-mvc-3 entity-framework list code-first
    I have a table of data with a list of key value pairs in it. Key Value ——————– ElementName PrimaryEmail Email [email protected] Value Content/Images/logo-here.jpgI am able to generate new items on my client webpage. When, I create a new row on the client and save it to the server by executing the following code the item saves to the database as expected.public ViewResult Add(CardElement cardElement) { db.Entry(obj).State = EntityState.Added

  • tugberk
    asp.net-mvc asp.net-mvc-3 entity-framework dbcontext
    On my ASP.NET MVC application, I am trying update two related models as follows:if (ModelState.IsValid) {_accommpropertyseasonrepo.Edit(accommPropertySeasonCreateViewModel.AccommPropertySeason);_accommpropertyseasonrepo.Save();_accommpropertyseasondetailrepo.Edit(accommPropertySeasonCreateViewModel.AccommPropertySeasonDetail);_accommpropertyseasondetailrepo.Save();return RedirectToAction(“Details”, new { id = id }); }First one is passing through with no problem but when it tries to update the se

  • SimpleUser
    mysql asp.net-mvc-3 optimistic-concurrency
    I’m trying to get my MVC3 application to use MySql database instead of Sql Server 2008. I have created the associated database and objects in Mysql. And Updated the connection string in my web.config file to reference MySql.Data.MySqlClient. When I run my application and try to login, I am getting the errorStore update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entrie

  • tugberk
    asp.net-mvc asp.net-mvc-3 validation entity-framework-4.1 ef-code-first
    I have been studying the EF for a short time and cant find the answer to this question. I have existing database and I am using CodeFirst to create classes for the model.What is the difference in using Attributes and EntityTypeConfiguration to define parameters of table columns?Since the database already has defined foreign keys and unique constraints, and so on, how and where to implement the validation for a best and most fluid result for use in ASP.NET MVC3?Is it better to implement Attribute

  • markpsmith
    asp.net-mvc-3 mvcmailer
    I tried to install MvcMailer and as soon as I added the package my project it died. I started getting all kinds of error messages concerning dependency conflicts with different versions of T4Scaffolding..versions 1.0.7 and 1.0.8. So I uninstalled the MvcMailer. When I run the program I still get the same message: A different version of T4Scaffolding is already running in this instance of Visual Studio Please restart Visual Studio to avoid unexpected behavior. You won’t be able to use scaffo

  • Charles
    asp.net-mvc-3 entity-framework validation
    I am having an issue with validation in EF models, that I cannot quite seem to figure out. The unobtrusive Javascript validation part works as expected.Consider the following models (the RequiredIf attribute is from this library):public class Conversation {public int Id { get; set; }public User User { get; set; }public String Handler { get; set; } }[ComplexType] public class User {public bool Anonymous { get; set; }[RequiredIf(“Anonymous”, false)][Display(Name = “Full name”)]public String Name {

  • xivo
    asp.net-mvc-3 entity-framework-4.1
    Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.I get this error, but I am the only person using the database. I am using Entity Framework 4.1 with DBContext.I am updating my records and SQL Profiler is showing a queue being sent in. What could be the causes of this issue?The post:[HttpPost]public ActionResult EditUser(User user){ uow.Us

  • Paul Keister
    razor asp.net-mvc-4 jquery-validate unobtrusive-validation
    While using ASP.NET MVC with unobtrusive validation enabled I have, on a number of occasions, had a need to embed an ID into a Razor form as a hidden field. I’ve learned to always include a validation message, for example:@Html.HiddenFor(x => x.ParentId) @Html.ValidationMessageFor(x => x.ParentId)If the validation message is left off, this will trigger a javascript error on submit, because the hidden field by default includes unobtrusive validation attributes which require a corresponding

  • TMan
    javascript html razor
    I have a list of rssobjects and I’m cycling through the list and displaying there properties on my view. On click I would like to send the rss objects summary property to the javascript function and then have it displayed on a modal but it doesn’t want to seem to work. The summaries are about 3000 characters long. I am getting an error: Uncaught SyntaxError: Unexpected token ILLEGAL It works if I send the title or the image url or if i manually set a ‘hello world’ on it. Could the summary be to

  • Derbie
    c# asp.net asp.net-mvc-4 razor
    I’d like to do something simple. I’ve got a list of products (of name of products indeed) with a “details” button next to each. When I click on the button, I want the details of the product to be displayed next to the list (unexpected, I know ^^). What I’ve done so far : The displaying of the list of products, that way :@foreach (var product in item.Value) {<div>id : @product.product.PRODUCT_ID , name : @product.product.PRODUCT_NAME @Html.ActionLink(“Details”, “ProductDetails”, new { id =

  • Chris Nelson
    razor asp.net-mvc-4
    I have a MVC3 project that has the following line of code which worked just fine:@if (this.Model.ShowAddButton) { @this.Html.ActionLink(“Add”, “Add”) }Our team has a coding guideline that all local method calls need to be prefixed with this. This has worked just fine in MVC3 up until now.I’ve manually upgraded the project to MVC4, using the guidance from here. Now the code above errors out with the following message: Unexpected “this” keyword after “@” character. Once inside code, you do not ne

  • Eranga
    c# asp.net-mvc asp.net-mvc-3 razor
    I need to modify the display of elements in my razor view depending on the value of a variable that’s in my model.What I have is Model.PartitionKey which is a six character string. I need to code an if statement that will check if the 3rd and 4th characters of this string are “00”. Here’s what I have so far:@using (Ajax.BeginForm(action,”Contents”,null,new AjaxOptions{UpdateTargetId = “update-message”,InsertionMode = InsertionMode.Replace,HttpMethod = “POST”,OnSuccess = success,OnFailure = “ajax

  • teresko
    c# asp.net-mvc asp.net-mvc-3 razor
    I have my controller working in a way at the moment where the url comes up Home/Collections/Collection?id=1 at the moment, which was my intended functionality. However, I would now like to make the url more friendly. For example, I would like it to become Home/Collections/Summer.I have the following code in my CollectionsController:public ActionResult Index(){return View(Helper.Helper.ResolvePath(“Collections”));}//// GET: /Collections/Collection?id=1public ActionResult Collection(int id){var co

  • gs11111
    asp.net-mvc asp.net-mvc-3 razor nerddinner
    I’m getting this error in my cshtml file near this code@{ var options = new OpenIdSelector();options.TextBox.LogOnText = “Log On”; }Parser ErrorDescription: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: Unexpected “{” after “@” character. Once inside the body of a code block (@if {}, @{}, etc.) you do not need to use “@{” to switc

  • Mattio
    asp.net-mvc-3 razor
    I’ve recently upgraded a project from MVC 1 to MVC 3 and now I’m trying out Razor.In one View, I have a foreach code block, but the nested if statement does not seem to want the @ in front of it.My original code was:@foreach(var r in Model.Results) {string css = r.Result.Count() > 0 ? “fail” : “pass”;<p class=”@css”><strong>@r.Description</strong></p>@if(r.Result.Count() > 0) {<p>Count: @r.Result.Count()</p><table><thead><tr><th>

  • dove
    c# asp.net-mvc razor
    ViewBag.EquipmentList = myInventoryEntities.p_Configurable_Equipment_Request_Select(Address_ID, false).Select(c => new { Value = c.Quantity + ” ” + c.Device_Name + ” (s)”, ID = c.Device_ID.ToString() }).ToList();In Razor i want to do the [email protected] Count is always == 1I know i can iterate in a foreach but would rather a more direct approach.Perhaps I am conceptually off?

  • Greg
    razor asp.net-mvc-4
    I’m using MVC4 and RazorI am getting unexpected results when I dynamically create a ActionLink and hoping somebody could explain why: The problem is that when I pass null as a htmlAttribute, the URL is generated correctly. However, when I pass in a value, the Area section of the URL are messed up.<li> @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName, rvd,link.ActionName.Equals(currentAction) && link.ControllerName.Equals(currentController)? new { @class = “curre

Web site is in building