asp.net-mvc-2

I can't add Microsoft.SqlServer.Management.Common to my ASP.NET MVC Application

隐身守侯 提交于 2019-11-30 05:59:46
问题 I am trying to add a reference to the above assembly but it does not appear in my ASP.NET MVC .NET 4 (Not client) applications Assembly list. Does anyone know how to reference this Assembly? 回答1: The Microsoft.SqlServer.Management.Common namespace resides in the Microsoft.SqlServer.ConnectionInfo.dll assembly. Microsoft.SqlServer.Management.Common Namespace (MSDN) Assuming the default installation folders you can find the Microsoft.SqlServer.ConnectionInfo.dll assembly in: C:\Program Files

CSS Background-Image refuses to display in ASP.Net MVC

流过昼夜 提交于 2019-11-30 05:58:29
问题 I am having trouble displaying an background image in my ASP.NET MVC 2 application. Currently, In ~/Views/Shared/Site.master, I set my link to the style sheet to: <link href="<%:@Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" /> The image I plan to display is in my ~/Content/Images/Designs.png Here is what I have tried body { background-image: url(~/Content/Images/designs.png); background-repeat: repeat; font-size: .75em; font-family: Verdana, Helvetica, Sans-Serif;

Is it a bad practice using model classes in controller in mvc?

主宰稳场 提交于 2019-11-30 05:22:35
问题 I wanted to compare with best practices when working with an ORM or database tables in asp.net mvc. One of the major questions I have is should I instantiate the model classes directly in controller..not query the database but just use the model class to store the values. For e.g. If I am using entity framework as model...then is it a bad practice to use the entity class objects in the controller . There are times when it is just easier to directly use the database classes generated in the

Remove Duplicate based on column value-linq

家住魔仙堡 提交于 2019-11-30 05:22:15
i have many to many relationship between employee and group. following linq statement int[] GroupIDs = {6,7}; var result = from g in umGroups join empGroup in umEmployeeGroups on g.GroupID equals empGroup.GroupID where GroupIDs.Contains(g.GroupID) select new { GrpId = g.GroupID,EmployeeID = empGroup.EmployeeID }; returns groupid and the employeeid. and result is GrpId | EmployeeID 6 | 18 6 | 20 7 | 19 7 | 20 I need to remove the rows for which the employeeid is repeating e.g. any one of the row with employeeid= 20 Thanks Jon Skeet Okay, if you don't care which employee is removed, you could

Reflect Over List of Controllers

梦想的初衷 提交于 2019-11-30 05:05:16
问题 I'm a bit new to reflection in c#. I'm trying to generate a list of all controllers in order to test whether or not they are decorated with a specific actionfilter. When writing unit tests, how do you access the tested assembly? This does not seem to work: var myAssembly = System.Reflection.Assembly.GetExecutingAssembly(); 回答1: If you know a type in your main assembly, you can use: private IEnumerable<Type> GetControllers() { return from t in typeof(MyType).Assembly.GetTypes() where t

Model Binding a Dictionary

☆樱花仙子☆ 提交于 2019-11-30 04:57:54
问题 My controller action method passes a Dictionary<string, double?> to the view. I have the following in my view: <% foreach (var item in Model.Items) { %> <%: Html.Label(item.Key, item.Key)%> <%: Html.TextBox(item.Key, item.Value)%> <% } %> Below is my action method which handles the POST operation: [HttpPost] public virtual ActionResult MyMethod(Dictionary<string, double?> items) { // do stuff........ return View(); } When I enter the some values into the textbox and hit the submit button the

Allowing asterisk in URL

余生颓废 提交于 2019-11-30 04:52:24
问题 I'm having a trouble allowing asterisk (*) in the URL of my website. I am running ASP.NET MVC 2 and .NET 4.0. Here's an example that describes the problem: http://mysite.com/profile/view/Nice* The username is Nice* and ASP.NET says there are illegal characters in the URL: Illegal characters in path. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code

ASP.net MVC v2 - Debugging Model Binding Issues - BUG?

删除回忆录丶 提交于 2019-11-30 04:44:45
I am having more than a little difficulty trying to debug why MVC is not binding correctly in a given case I have... Basically, I have my action which receives a complex object which in turn has a complex child object - Activity.Location.State (Where Activity is the complex object that the action expects, Location is a complex child object and State is just a string). Now I set up a test project which as far as I can tell exactly mimics the actually scenario I have, in this test case the binding works... But in my actually project, the binding to Activity works but not to Location... By

Error: The entity or complex type cannot be constructed in a LINQ to Entities query

南楼画角 提交于 2019-11-30 04:38:50
问题 I get this error "System.NotSupportedException: The entity or complex type 'MyModel.Team' cannot be constructed in a LINQ to Entities query." when I navigate to the Team/Index/{id} page. Can someone point me to the mistake I did please? Controller: public ActionResult Index(int id) { IQueryable<Team> teams = teamRepository.GetTeamByPersonID(id); return View("Index", teams); } Repository: public IQueryable<Team> GetTeamByPersonID(int id) { return from t in entities.Teams join d in entities

Providing or Filtering assemblies when registering areas for an ASP.NET MVC 2.0 application

房东的猫 提交于 2019-11-30 04:14:23
I have a large application that currently exists as a hybrid of WebForms and MVC 2.0. Startup of my application is dreadful, and the culprit is primarily because of the AreaRegistration.RegisterAllAreas call. More specifically, that it is using the System.Web. Compilation.BuildManager.GetReferencedAssemblies to enumerate all types in assemblies directly referenced by the application and test them to see if they derive from AreaRegistration . Unfortunately, I have a number of third-party assemblies that happen to be quite extensive, so this initial load can be pretty bad. I'd have much better