asp.net-mvc-2

SelectList to filter results based on sql tables bool column for “Retired”

感情迁移 提交于 2019-12-06 19:21:24
I have a selectlist which I've setup in a ViewModel and DropDownFor and it already has itself ordered as u can see below but I need it to filter so that the 3rd column "Retired" if it's value is "0" all those results are show but not if it's "1". I was thinking I would need to add after the .OrderBy(...).Where(m=>m.Retired but don't know how exactly I'd filter it from there and ofc it doesn't have to be done in the VM but that's just how I was able to implement the OrderBy filter. VM List<Reason> reasonList = _db.Reasons.OrderBy(m=>m.Description).ToList(); ReasonList = new SelectList

Can ASP.NET MVC html helpers render an element without an ID attribute?

跟風遠走 提交于 2019-12-06 18:43:14
问题 Assume I want to generate an element similar to this in ASP.NET MVC 2: <%= Html.TextBoxFor(p => p.FooBar)%> Is there an overload or way I can get ASP.NET MVC 2 to only generate a name attribute and not an ID attribute? I can have it generate a blank id with <%= Html.TextBoxFor(p => p.FooBar, new { id = "" })%> , but I would like to generate the element with no ID at all, and without overriding the asp.net mvc framework. 回答1: The behavior of the HTML helpers was changed as of MVC 2 RC1 so that

Can you pass a model with RedirectToAction?

萝らか妹 提交于 2019-12-06 17:40:40
问题 I'm using mvc 2 release candidate, and am wondering if there's any way to pass a model to an action using RedirectToAction. For example, I have an edit action which takes an ID, and loads the record from a database, displays the current values in text boxes and lets the user edit and click submit: public ActionResult Edit(int ID) Then I have an edit action for the HttpPost which takes a model and updates the database: [HttpPost] public ActionResult Edit(Administration.Models

Stored procedure or LINQ? [closed]

六月ゝ 毕业季﹏ 提交于 2019-12-06 16:37:46
Closed . This question is opinion-based . It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . Closed 5 years ago . I have a webshop created in ASP.net MVC 2 with a database SQL server. If I need to make filtration for instance specfic products from the stock in database via webshop. Which options should I choose and why? Make the filtration via stored procedure? Using LINQ as a C-sharp coding? Another solution? I would only use stored procedure if you really want to optimize your sql.

How EditorFor set ID and Name html attributes on form elements

三世轮回 提交于 2019-12-06 16:30:14
I have few layers of nesting custom user controls: RegisterUser.aspx <%@ .... Inherit="System.Web.Mvc.ViewPage<RegisterUserViewModel>" ... <%= Html.EditorFor(m => m.Details) %> ... UserDetails.ascx <%@ .... Inherit="System.Web.Mvc.ViewUserControl<UserDetails>" ... <%= Html.EditorFor(m => m.BirthDate) %> <!--BirthDate is of type DateTime--> ... and I have declared DateTime.ascx in Shared/EditorTemplates <%@ .... Inherit="System.Web.Mvc.ViewUserControl<dynamic>" ... <input type="text" id="???" /> ... The question is how to set input id attribute? I know that EditorFor makes some magic for

ASP.NET Calendar OnSelectionChanged handler not getting called

﹥>﹥吖頭↗ 提交于 2019-12-06 16:02:02
Can some please tell me why the event handler named "MyCalendar_SelectionChanged" is not getting executed when I click on a day within calendar control? This is the simple aspx code from a sample ASP.NET MVC2 application: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> <script runat="server"> private void MyCalendar_SelectionChanged (object sender, System.EventArgs e) { //lbl1.Text = Calendar1.SelectedDate.ToString(); Console.WriteLine("test"); } </script> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">

Custom IRouteHandler route screws up MVC link building

佐手、 提交于 2019-12-06 15:53:04
I have a custom routehandler in ASP.NET MVC2 to catch all url's at a prefixed path like this: routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.Add(new Route("@api/{*all}", new ApiHandler())); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); Routing works fine, but if i use Html.Actionlink or return ReturnToAction() from a controller, the uri built creates a broken uri like this: /@api?action=Add&controller=Home instead of /Home/Add How can i

ASP.NET MVC 2 Beta single-project Area registration getting HTTP 404

假装没事ソ 提交于 2019-12-06 15:47:35
I'm trying to get ASP.NET MVC 2 single-project area registration to work. Tried with Preview 2 and now with Beta version with no luck. I used the "Add area" dialog to create a "NewsModule" area. Created a NewsModuleController inside it and an Index view for it. The route registration for this Area looks like this: context.MapRoute( "NewsModule_default", "NewsModule/{action}/{id}", new { action = "Index", id = "", controller = "NewsModule", area = "NewsModule" } ); I added the AreaRegistration.RegisterAllAreas(); call to my Global.asax. Accessing http://localhost/mymvcproj/NewsModule gets a

Error when creating crystal report in asp.net mvc2

China☆狼群 提交于 2019-12-06 15:44:54
I made a report using crystal report and in the page load I am writing this protected void Page_Load(object sender, EventArgs e) { ReportDocument crystalReport = new ReportDocument(); crystalReport.Load(Server.MapPath("CrystalReport.rpt")); crystalReport.SetDatabaseLogon ("amit", "password", @"AMIT\SQLEXPRESS", "TestDB"); CrystalReportViewer1.ReportSource = crystalReport; } and when runing the page I found this error. CS0433: The type 'CrystalDecisions.Web.CrystalReportViewer' exists in both 'c:\Windows\assembly\GAC_MSIL\CrystalDecisions.Web\10.5.3700.0__692fbea5521e1304\CrystalDecisions.Web

Fixture.CreateAnonymous method kills test runner process with an error (AutoFixture) when using AutoMoq to create a Controller

不打扰是莪最后的温柔 提交于 2019-12-06 15:00:23
I'm trying to use the AutoMoqCustomization with AutoFixture to create an ASP.NET MVC2 Controller in a unit test via the Fixture.CreateAnonymous method. I've tried in both xUnit under TestDriven.NET, the xUnit test GUI and in MSTest and all have the same result: a massive failure of the process running the test. On Windows 7 x64 if that matters. To reproduce, simply create a new ASP.NET MVC2 project, add the references to AutoFixture, AutoMoq and Moq (3.1, as per the AutoMoq source) and try the below (repro VS2010 MVC2 project link below): [TestMethod] public void Index() { var fixture = new