asp.net-mvc-2

disable button when first click in jquery

假如想象 提交于 2019-12-08 08:34:57
问题 I want to disable button when user first click it so it must not save multiple record if a user have a slow connection. Im using asp.net mvc2 回答1: $('#buttonId').click(function() { $(this).attr('disabled', 'disabled'); }); Of course you have to adjust the selector. 回答2: You can use jQuery's one(). With this, the event handler is executed only once. Inside the event handler you can disable or change the style. Example from jQuery site: $('#foo').one('click', function() { alert('This will be

ASP MVC 2 Uploading file to database (blob)

☆樱花仙子☆ 提交于 2019-12-08 08:28:04
问题 I am trying to upload a file via a form and then save in in SQL as a blob. I already have my form working fine, my database is fully able to take the blob and I have a controller that take the file, saves it in a local directory: [AcceptVerbs(HttpVerbs.Post)] public ActionResult FileUpload(int id, HttpPostedFileBase uploadFile) { //allowed types string typesNonFormatted = "text/plain,application/msword,application/pdf,image/jpeg,image/png,image/gif"; string[] types = typesNonFormatted.Split('

How can host name be included in MVC2 route mapping?

喜夏-厌秋 提交于 2019-12-08 07:54:41
问题 I've got 3 domain names all pointed at the same MVC2 application. What I've got now is the homecontroller acting as a traffic cop and redirecting to controllers and views for the specific host name. But I don't like the URI result this causes... ex: www.webhost1.com/webhost1/imagegallery www.webhost2.com/webhost2/imagegallery I'd prefer to have: www.webhost1.com/imagegallery Is there a way to define the routes in global.asax that would include the host name in the routing evaluation so that

ASP.NET MVC how can I return an error from a file download action without leaving the current page?

雨燕双飞 提交于 2019-12-08 07:51:08
问题 I am calling a file download action from javascript: $elem.click(function() { window.location.href = 'MyController/MyFileDownloadAction'; }); The controller returns a file: [AcceptVerbs(HttpVerbs.Post)] public ActionResult MyFileDownloadAction() { /* do some processing, generate an in-memory file... */ return File(myFileStream, "text/plain", myFileName); } This action has a pretty high likelyhood of throwing an exception (or at least not being able to return the file). Due to the nature of

ASP.NET MVC - How do I load an image asynchronously?

China☆狼群 提交于 2019-12-08 07:14:27
问题 On the home page of my site I want to display a lot of products which have images which are quite large. Currently the page is taking so long to load that it is actually timing out and the page fails to display! In MVC, or just ASP.NET in general, how can I load an image asynchronously? Basically what I want to do is display the details of the product and just display a small loading image e.g. ajaxload.info. until the image is loaded. I assume this is going to require some javascript/jQuery.

Url.Content on Azure

邮差的信 提交于 2019-12-08 07:05:00
问题 I have an ASP.NET MVC 2 application that has page with a link to a pdf file <a href="<%= Url.Content("~/Downloads/test1.pdf") %>">test1</a> Downloads directory is at MVCApplication1/Downloads This works fine locally and on ISS, but returns a page not found when uploaded to Azure. 回答1: Check the path that is being emitted in the HTML. Its likely relative to the Azure datacenter/cluster, and is meaningless to your client if your client is outside Azure. If you see something like "http:/

Optimizing C# code in MVC controller

ε祈祈猫儿з 提交于 2019-12-08 06:33:51
问题 I am making a number of distinct controllers, one relating to each stored procedure in a database. These are only used to read data and making them available in JSON format for javascripts. My code so far looks like this, and I'm wondering if I have missed any opportunities to re-use code, maybe make some help classes. I have way too little experience doing OOP, so any help and suggestions here would be really appreciated. Here is my generalized code so far (tested and works); using System;

how to get partialview data in controller

杀马特。学长 韩版系。学妹 提交于 2019-12-08 05:47:28
问题 I am using 3 partialview on a single view, I have a submit button on clicking of which I want to send information to database, I have to retrieve data from all the partialview. Can You please provide me correct information to do it. Darin I m using L2S so when I drag my stored procedure, I get code some thing like this in [global::System.Data.Linq.Mapping.FunctionAttribute(Name="SP_Name")] public int SP_Name( [global::System.Data.Linq.Mapping.ParameterAttribute(Name="EmployeeID", DbType="Int"

Funky Sql Generated using SubSonic Simple Repository, LINQ and ASP.NET MVC

泪湿孤枕 提交于 2019-12-08 05:46:56
问题 I have the following code: if (collection["Filter"] == "2") { presentations = presentations.Where(x => x.Speaker.FirstName.StartsWith("B")). OrderBy(x => x.Speaker.FirstName); } this generates the following sql: SELECT [t0].[Description], [t0].[EventId], [t0].[Id], [t0].[PresentedOn], [t0].[Slug], [t0].[SpeakerId], [t0].[Title], [t0].[Url] FROM [Presentations] AS t0 LEFT OUTER JOIN [Speakers] AS t1 ON ([t1].[Id] = [t0].[Id]) WHERE ([t1].[FirstName] LIKE 'B' + '%') ORDER BY [t1].[FirstName]

Passing Controller a FormCollection and an IList<T>

℡╲_俬逩灬. 提交于 2019-12-08 04:54:48
问题 I have a form which contains a whole heap of data entry fields that will be completed by the user including some elements where the user can dictate how many of the same items they will enter. This is as is being used in Phil Haack's blog entry Model Binding To A List. I am successfully using JQuery to create the extra form elements, correctly indexed, etc. My issue is the best way to actually read these within my Controller. The Controller in the article only expects one object, IList