asp.net-mvc-2

Why should I use GetOriginalEntityState() in my LINQ To SQL repository save method?

£可爱£侵袭症+ 提交于 2019-12-04 07:01:59
I'm looking at an example of a save method in a Products repository from Steven Sanderson's book, Pro ASP.NET MVC 2 Framework: public void SaveProduct(Product product) { // if new product, attach to DataContext: if (product.ProductID == 0) productsTable.InsertOnSubmit(product); else if (productsTable.GetOriginalEntityState(product) == null) { // we're updating existing product productsTable.Attach(product); productsTable.Context.Refresh(RefreshMode.KeepCurrentValues, product); } productsTable.Context.SubmitChanges(); } I do not understand the logic in the else if line: else if (productsTable

What's the difference between the database inside App_Data folder vs connecting to SQL Server?

偶尔善良 提交于 2019-12-04 06:55:37
I'm new to .NET and while starting to learn ASP .NET MVC2 framework I see that you can create a .mdf file inside the App_Data folder and connect to it or you can connect to a SQL Server. What is the difference between these to methods of interacting with a database? What are the advantages/disadvantages of one over the other? The "MDF in the App_Data" folder works for web site and web apps, and it works only with SQL Server Express (2005, 2008, 2008 R2). This is the version that's typically installed along with Visual Studio, and which works fine as a dev environment. SQL Server Express has a

ASP.NET MVC2 Model Validation Fails with Non-US Date Format

爱⌒轻易说出口 提交于 2019-12-04 06:36:53
I have a small MVC2 app that displays in two cultures: en-US and es-MX. One portion contains a user input for a date that is pre-populated with the current date in the Model. When using en-US, the date field is displayed as MM/dd/yyyy and can be changed using the same format without causing any validation errors. When using es-MX, the date field is displayed as dd/MM/yyyy, but when the date is edited in this format, the server-side validation fails with the message: The value '17/05/1991' is not valid for The Date. One of the first things that jumps out at me about that message is that it is

ASP.NET MVC how to make an action that return a file?

旧时模样 提交于 2019-12-04 06:22:43
Hello I am generating an excel file inside my action that I would return to the user. How do I have to declare the action to return a file? May I call this action with ajax? thanks! Retired_User Option 1: Use built in ActionResults, such as FilePathResult, FileStreamResult, FileContentResult Option 2: Build a custom ActionResult to return your excel file (example: http://www.dotnetcurry.com/ShowArticle.aspx?ID=484&AspxAutoDetectCookieSupport=1 ) 来源: https://stackoverflow.com/questions/3935225/asp-net-mvc-how-to-make-an-action-that-return-a-file

Asp.Net MVC : Execution of the child request failed. Please examine the InnerException for more information

假装没事ソ 提交于 2019-12-04 06:05:35
I'm recieving the following error message, A public action method 'RenderMenu' was not found on controller 'Web.Controllers.SiteController'. However this action DOES exist and the controller does exist (As it work everywhere on the site) I looked at the inner exception. Execution of the child request failed. Please examine the InnerException for more information. (This is the inner exception...) Stack Trace at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func`1 func) at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean

How to use ASP.Net MVC View inside WebForms .aspx page?

吃可爱长大的小学妹 提交于 2019-12-04 05:45:48
I have a large web application that I have set up as both ASP.Net Web Forms and MVC. Some of the newer pages are MVC (.mvc) and some are Web Forms (.aspx). Since this is a business app and functions are being constantly added, it's hard for me to have the time to stop and replace existing functionality to convert it over. So I would like to do it piece by piece, control by control. To do this, all I would need to be able to do is to replace certain controls with <% Html.RenderPartial() %> or <% Html.HelperMethod %> Is it possible to include namespaces or inherit the page from something to

PostAuthenticateRequest fires several times

拜拜、爱过 提交于 2019-12-04 05:25:57
I have Forms authentication and I need a custom object to be stored in HttpContext.Current.User and in Thread.CurrentPrincipal. To get this, I listen to PostAuthenticateRequest event, then read from the DB all the user data I need to be stored in HttpContext.Current.User and in Thread.CurrentPrincipal, then I instantiate custom IPrincipal and IIdentity objects and assign them to the above locations. The problem is that for some reason PostAuthenticateRequest fires several times for a single request.. This causes unnecessary DB roundtrips that hurt performance.. How should I address this? (ASP

Translate to razor Syntax from MVC 2.0 code

混江龙づ霸主 提交于 2019-12-04 05:21:38
问题 I am trying to convert the popular asp.net MVC 2.0 solr.net sample app code to Razor syntax. I am not able to understand the last line ... Kindly help <% Html.Repeat(new[] { 5, 10, 20 }, ps => { %> <% if (ps == Model.Search.PageSize) { %> <span><%= ps%></span> <% } else { %> <a href="@Url.SetParameters(new {pagesize = ps, page = 1})">@ps</a> <% } %> <% }, () => { %> | <% }); %> [update] Source for Html.Repeat extension HtmlHelperRepeatExtensions.cs 回答1: For this to work you will have to

MVC2 RTM - model binding complex objects using Entity Framework

别来无恙 提交于 2019-12-04 05:19:37
问题 I am new to MVC, and am really struggling with what I seems like it should be a very common scenario. I'm using MVC2 RTM, and the Entity Framework for my model objects. What I have working: An edit view for a parent object that contains a collection of child objects. The form displays all the editable fields for the parent, and iterates through and displays all editable fields for all the associated child objects (in the same view). I am able to successfully handle the edit action in my

Html.Editor not rendering the value

淺唱寂寞╮ 提交于 2019-12-04 05:18:22
问题 I'm having problems making the Html.Editor rendering the desire HTML. Here is the scenario: // assign the value ViewBag.BeginDate = seaBeginEnd.beginDate; //View @Html.Editor("Begin", ViewBag.BeginDate as DateTime?) //HTML Source <div class="editor-field"> <input class="text-box single-line" id="Begin" name="Begin" type="text" value="" /> </div> I was specking to see a value of 1/19/2011 12:00:00 AM which is the value of ViewBag.BeginDate, any insights. Thanks for your help! 回答1: I was