asp.net-mvc-2

Export html table to excel in asp.net MVC2

做~自己de王妃 提交于 2019-11-29 08:10:50
Hi am looking for the best way on how export to excel does in ASP.NET MVC Now i got this one from billsternberger.net Export to Excel or CSV from ASP.NET MVC with C# //Export to excel public ActionResult Download() { List<Lookup> lookupList = data,GetLookupList(); var grid = new System.Web.UI.WebControls.GridView(); grid.DataSource = lookupList; grid.DataBind(); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=YourFileName.xlsx"); Response.ContentType = "application/vnd.ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new

Possible to use ASPNET MVC2 without IIS?

无人久伴 提交于 2019-11-29 07:54:52
I know of the ServiceHost class, that lets me write a custom host for a WCF service. This means there's no requirement for IIS. (I also know all the advantages of using IIS - no need to rehash those for me.). Is there something similar to allow me to host ASPNET MVC2, without IIS? Conversely, Is IIS a hard requirement for ASPNET MVC2? Has anyone used UltlDev Cassini , and if so, what are your experiences? Will it run ASPNET MVC2? (I am using .NET 3.5) You can run it on Cassini, Mono, IIS or host the whole asp.net runtime in your own application. (Actually pretty easy) 来源: https://stackoverflow

Validation messages are displayed when page load

与世无争的帅哥 提交于 2019-11-29 07:46:22
问题 I have a problem with validation in ASP.NET MVC 2.0. I use the same Action in Controller to perform user request. For example: public ActionResult Index(ReportModel model) { if (!model.IsInitialDisplay && ModelState.IsValid) { model.Result = service.GetResult(model); } return View(model); } In the ReportModel, I define a flag IsInitialDisplay to determine whether the page is initial displayed or not: public class ReportModel { [Required(ErrorMessage = "*")] public string Criteria { get; set;

Convert JSON dates without timezone

拈花ヽ惹草 提交于 2019-11-29 07:32:41
I have a webservice that returns for example a DateTime object: DepartureDate. I use ajax to fetch this and in my view I convert the JSON date string to a javascript date object with this function: function convertToDate(jsonDate) { return eval("new " + jsonDate.substring(1, jsonDate.length - 1)); } The problem is that new Date() takes the local time on the clients computer in consideration, so clients in different countries get different dates. I want to get the exact date that was returned from the webservice. Is there any easy way to accomplish this? The problem is that new Date() takes the

Property-level validation errors hinder the validation of Class-level validation

拈花ヽ惹草 提交于 2019-11-29 07:12:14
Update after Bounty was awarded A new solution is coming up to this problem. Please refer to ASP.NET MVC 3 Preview 1 here: http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx Look in the section Model Validation Improvements , where you will see the solution to my problem. Original Post Referring to my earlier post How to validate two properties with ASP.NET MVC 2 where I asked how I could compare two properties for Model validation. I did find the answer useful, but I was left with an entirely different problem: Problem : If a Property-level

Code First adding to collections? How to use Code First with repositories?

时间秒杀一切 提交于 2019-11-29 05:52:10
EDIT: This happen only on larger scale projects with repositories. Is there anybody using EF4 with CodeFirst approach and using repositories? Please advise me. Hi. Im currently working with EF4 CodeFirst Classes. In my test project I got two classes, Author and Book (author got books). What I'm trying to do is that I have a AddBook in my Author class, but that wont seem to work like I can't Add it to the collection.. here are my classes and two different exceptions. public class Book { public virtual int BookId { get; set; } public virtual string Title { get; set; } public virtual Author

Why am I getting ::1 as IP address in ASP.Net.. and how to get the proper IP address?

雨燕双飞 提交于 2019-11-29 05:44:19
I am running a ASp.Net mvc app in localhost - dev server given with visual studio. I want to get the IP address. I tried Request.UserHostAddress and Request.ServerVariables("REMOTE_ADDR") In both cases, I am getting ::1 as the result. What is it? Why am I getting it? How can I get 127.0.0.1 or 192.168.1.xxx? You are getting a valid IP Address. ::1 is local_host in IPv6. (underscore used in local_host to stop SO from thinking it was some sort of bad text) What you're seeing when calling 'localhost' is valid. ::1 is the IPv6 loopback address. Equivalent to 127.0.0.1 for IPv4. Instead of calling:

How to validate two properties with ASP.NET MVC 2

拟墨画扇 提交于 2019-11-29 04:40:59
I'm just getting started with ASP.NET MVC 2, and playing around with Validation. Let's say I have 2 properties: Password1 Password2 And I want to require that they are both filled in, and require that both are the same before the model is valid. I have a simple class called "NewUser". How would I implement that? I've read about ValidationAttribute, and understand that. But I don't see how I would use that to implement a validation that compares two or more properties against eathother. Thanks in advance! Problem with below solution : When this is applied to an application, and the ModelBinder

MVC RoleProvider and Authorize attribute

时光总嘲笑我的痴心妄想 提交于 2019-11-29 04:23:05
I have implemented my own role provider, and I'm not using the default one. It works to the point that it can tell when someone should or should not be able to view a page. However, can it do the following: If a user is not logged in, redirect to my login page If a user IS logged in but does not have the correct role, redirect to a different page I haven't figured out how to do this with the Authorize attribute, all I have is: [Authorize(Roles="Admin")] Basically I need to redirect to a different page based on what part of the authorization fails. I've looked to see if it were something in web

How can I create more than one editor template for a multi-line textbox in MVC3?

淺唱寂寞╮ 提交于 2019-11-29 04:09:05
I have the following two types of multiline textareas in my views: <textarea cols="100" rows="15" class="full-width" id="dialogText" name="Text">@Model.Text</textarea> <textarea cols="100" rows="10" class="full-width" id="dialogText" name="Text">@Model.Text</textarea> I would like to take advantage of custom editor templates, but keep the ability to specify attributes differently (e.g. the rows are different between the two above). Is it possible for me to declare and use two different kinds of templates for the same field? If so then how should I declare the template and how do I specify the