asp.net-mvc-2

Where to write Database and Business logic in MVC?

心不动则不痛 提交于 2019-11-30 11:34:11
As I am learning and working on Asp.Net MVC application, I want to know that what is the better place to write Business Logic and Data Access logic in MVC . Where should I write DataAccess and Business Logic among three layers ( Model, View and Controller ) ?? Could anybody please tell me the correct way to write the code for this. Scenario: I want to retrieve all the employees where employee name like 'Mi%' ( I have SQL procedure to execute and retrieve the data. ) PS: Want to know that where I should create instance of Business Logic class and where I should create instance of Data Access

How to define form field prefix in ASP.NET MVC

点点圈 提交于 2019-11-30 11:33:51
I am attempting to render a composite ProductCatalog view in ASP.NET MVC. This requires that I render multiple Product views per page. Each product view is a separate form. I need the form fields to have a prefix based on the id, so that I don't have duplicate IDs in the rendered document. Is there a way to define a prefix to be applied to all the form fields that are generated by the Html Extensions, or do I need to build this out manually? Yes, you can define a prefix for the controls inside your view based on the executing action, consider the following code that should be place in your GET

BinaryWrite exception “OutputStream is not available when a custom TextWriter is used” in MVC 2 ASP.NET 4

别说谁变了你拦得住时间么 提交于 2019-11-30 11:18:51
I have a view rendering a stream using the response BinaryWrite method. This all worked fine under ASP.NET 4 using the Beta 2 but throws this exception in the RC release: "HttpException" , "OutputStream is not available when a custom TextWriter is used." <%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %> <%@ Import Namespace="System.IO" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (ViewData["Error"] == null) { Response.Buffer = true; Response.Clear(); Response.ContentType = ViewData["DocType"] as string; Response.AddHeader("content

Display empty textbox using Html.TextBoxFor on a not-null property in an EF entity

谁说胖子不能爱 提交于 2019-11-30 11:11:33
I am using Entity Framework (v4) entities. I have an entity called Car with a Year property of type integer. The Year property does not allow NULL. I have the following in my Create view: <%= Html.TextBoxFor(model => model.Year) %> I am required to return a new Car object (due to other requirements) in my HttpGet Create action in the CarController. Currently, a zero is displayed in the Year textbox because the Year property does not allow NULL. I would like to display an empty textbox in the Create view. How do I do this? Use Html Attributes Overload. In razor it would be: @Html.TextBoxFor

Custom Data Annotations ASP.NET MVC C#

岁酱吖の 提交于 2019-11-30 10:51:56
问题 I have the follwing question about MVC 2 with C#. Here is my Model: public class Pmjob { [Tooltext="Hier soll der Name eingegeben werden"] [DisplayName("Type")] public int Name { get; set; } } Now I want to reach the Tooltext item in my view, e. g.: @Html.ToolTextFor(Model => Model.Pmjob.Name) or in the BL: if ( Model.Pmjob.Name.Tooltext == "") { } Is this possible? 回答1: Create an abstract class MetaDataAttribute : public abstract class MetadataAttribute : Attribute { /// <summary> /// Method

Disable or enable Submit button on Checkbox checked event

此生再无相见时 提交于 2019-11-30 10:09:04
I want something like this but with a slight change. I want a Button to be enabled or disabled on Checkbox checked event, i.e. when checkbox is checked then and then only button should be enabled otherwise it is disabled. This should be done using jQuery Code not JavaScript. As this is MVC form so there is no Form ID. $(function() { $('#id_of_your_checkbox').click(function() { if ($(this).is(':checked')) { $('#id_of_your_button').attr('disabled', 'disabled'); } else { $('#id_of_your_button').removeAttr('disabled'); } }); }); And here's a live demo . This is old but worked for me with jquery 1

MVC route with array of homogeneous parameters

烈酒焚心 提交于 2019-11-30 10:07:47
I trying to create routes for a resource with an array of homogeneous parameters. URL would look like this: products/category/{categoryId1}/{categoryId2}/.../brand/{brandID1}/{brandID2}/... And would like an action method would look like this: public ActionResult GetProducts(IList categoryID, ILIsts brandID) {...} where category and brand are independent filters. I found a solution for similiar task: ASP.NET MVC 2 Parameter Array And wonder if there is no more beautiful solution that allow to use this prototype public ActionResult GetProducts(IList categoryID) instead of public ActionResult

Could not load file or assembly 'System.Web.Mvc' or one of its dependencies

夙愿已清 提交于 2019-11-30 09:26:47
I have this new MVC application which I have installed on Windows 2008 Server. And get the following message when I run the localhost. I have checked in the Bin folder, and can confirm that the Systems.Web.MVC is there. And the version of the file is, 2.0.50217.0 And in the web.config I have defined this assembly, Can any one help? See the error message below: ----ERROR MESSAGE------------------------------ Server Error in '/' Application. -------------------------------------------------------------------------------- Could not load file or assembly 'System.Web.Mvc' or one of its dependencies

Strongly Typed ActionLink In Asp.Net MVC 2?

萝らか妹 提交于 2019-11-30 09:01:56
I just downloaded VS.NET 2010 RC and created a new MVC project. It would seem that strongly typed ActionLinks are not in this release? Is this always going to be a "futures" thing? Or am I missing something? <%=Html.ActionLink<HomeController>(x => x.Index(),"Home")%> No there is no ActionLink<> see ScottGu blog (( For performance reason. re: ASP.NET MVC 2: Strongly Typed Html Helpers Tuesday, January 12, 2010 2:32 AM by ScottGu @Anthony, but what about strongly typed ActionLinks? We aren't adding built-in runtime helpers for this - but David Ebbo has created a nice VS tooling add-on that

ASP.NET MVC ModelMetaData: Is there a way to set IsRequired based on the RequiredAttribute?

旧时模样 提交于 2019-11-30 08:36:22
Brad Wilson posted a great blog series on ASP.NET MVC's new ModelMetaData: http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-2-modelmetadata.html In it, he describes how the ModelMetaData class is now exposed in the Views and templated helpers. What I'd like to do is display an asterisk beside a form field label if the field is required, so I thought about using the IsRequired property of ModelMetaData. However, IsRequired by default is true for all non-nullable properties, while it's false for all nullable properties. The problem is, strings are always nullable, so the