Tag: asp.net

如何使用匿名LINQ结果填充DataTable

我有以下LINQ查询: var timesheets = from timesheet in entities.Timesheets join timesheetTask in entities.Timesheet_Task on timesheet.Id equals timesheetTask.Timesheet_Id join task in entities.Tasks on timesheetTask.Task_Id equals task.Id join project in entities.Projects on task.Project_Id equals project.Id join department in entities.Departments on project.Department_Id equals department.Id where timesheet.Employee_Id == employeeId select new { date = timesheet.Date, taskName = task.Name, projectName = […]

多重约束违反了entity framework5

你好我有3个类Person,UserProfile(它inheritance了Person)和Results,一个Person可以有一个或多个结果,当我尝试将ia结果添加到一个人时ai得到标题中提到的错误,我的类是下面的。 任何帮助,将不胜感激。 [Table(“People”)] public class Person : IPerson { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Name { get { return FirstName + ” ” + LastName; } set{} } public string Email { get; set; } […]

ASP.NET MVC 2问题 – Dot in Route

我正在消隐,需要一个快速的手。 谷歌让我失望了。 我正在努力用ASP.NET MVC替换WCF / REST入门套件。 我希望尽可能轻松地进行转换,因此我尝试创建一个匹配以下URL的路由: http://localhost/services/MyService.svc/UserInfo 我在Global.asax.cs中创建了路由: routes.MapRoute( “MyServiceDefault”, “services/MyService.svc/{action}/{id}”, new { controller = “MyService”, action = “UserInfo”, id = UrlParameter.Optional } ); 我很快就意识到这个请求甚至没有通过我的应用程序. 在URL的MyService.svc部分。 我错过了什么来强制请求传递到我的应用程序而不是由服务器作为静态资源处理? 更新 我忘了提到我还尝试将以下内容添加到Web.config无济于事:

发送HTTP标头后,服务器无法设置内容类型

我在以下代码( ContentType行)上收到错误(服务器无法在发送HTTP标头后设置内容类型。)。 我应该改变什么? System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; response.ClearContent(); response.ContentType = “text/plain”; response.AddHeader(“Content-Disposition”, “attachment; filename=” + System.IO.Path.GetFileName(PervasiveConstants.DownloadZipLocation) + “;”); response.TransmitFile(PervasiveConstants.DownloadZipLocation); response.Flush(); response.End(); 这是在Sharepoint 2010 webpart中。

如何在LinkBut​​ton点击事件上启动电子邮件客户端?

如何启动Outlook电子邮件窗口(类似于mailto:在超链接中执行的操作)? 这需要在LinkButton点击事件中完成。

如何在asp.net 5中为“asp-for”传递字符串值

我想为具有许多属性的实体编写Edit.cshtml文件,因此我必须多次编写以下代码: 实际上,有很多实体,所以我必须编写许多Edit.cshtml文件。 我想做一些简化 我想在控制器中选择实体的一些属性,并使用循环来显示视图中的属性。 例如:在控制器文件中: public IActionResult Edit(string id) { var model = GetModel(id); var propertyNames= new List() { “Name”, “Email” // add some other property names of the entity }; ViewData[“PropertyList”] = propertyNames; return View(model); } 在视图文件中: @{ var propertyNames = (List)ViewData[“PropertyList”]; foreach (string item in propertyNames) { } } 但它无法工作,因为它会产生错误的代码。 似乎我无法为“asp-for”标签助手传递字符串值。 例如,如果我将top的代码更改为: @{ […]

使用Entity Framework的Model上的DisplayName

我有一个代码如下: public class MyModel { [Required] [Display(Name = “labelForName”, ResourceType = typeof(Resources.Resources))] public string name{ get; set; } } 问题是在生成的Entity Framework模型类中添加了属性Display和Required。 我知道我可以使用Partial添加function但是如何将属性添加到将使用ORM擦除和更新的类?

如何获取缓存项目的到期日期?

我在MemoryCache中存储一个对象: void foo() { ObjectCache cache = MemoryCache.Default; SomeClass obj = cache[“CACHE_KEY”] as SomeClass; if (null == obj ) { obj = new SomeClass(); …. CacheItemPolicy policy = new CacheItemPolicy(); //update policy.AbsoluteExpiration = DateTime.Now+TimeSpan.FromMinutes(1); cache.Set(“CACHE_KEY”, obj, policy); } else { //get expiry date } ….. } 如果缓存包含对象,是否有可能以某种方式获得到期日期?

如何撤消Response.Cache.SetNoStore()?

我有一个CMS应用程序代码,它在所有请求上调用Response.Cache.SetNoStore() ,如果我是正确的,这将阻止代理/ cdn缓存这些页面/内容。 因此,我有条件地调用以下代码: Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetMaxAge(new TimeSpan(0, 30, 0)); Response.Cache.SetValidUntilExpires(true); 但这并没有从响应头中取出no-store参数,这是返回的http头: Cache-Control:public, no-store, must-revalidate, max-age=1800 因此,我的问题是,如何才能真实地取出nostore param? 如果这是不可能的,我如何/在哪里解析/修改http-header,因为我试图在PagePreRender事件上解析并且nostore param尚未应用…这导致想知道哪个生命周期是这个附加到标题?

以编程方式创建asp:Button?

我正在使用我的代码隐藏页面以编程方式创建一个保存按钮: Button btnSave = new Button(); btnSave.ID = “btnSave”; btnSave.Text = “Save”; 但是我认为这必须创建一个html按钮或者可能需要其他东西,因为我似乎无法在下一行中设置OnClick属性,我可以指定OnClientClick,但这不是我想要设置的。