我需要在一个linq查询中使用lambda表达式调用ToShortDateString:
toRet.Notification = Repositories
.portalDb.portal_notifications.OrderByDescending(p => p.id)
.FirstOrDefault(p => p.date.ToShortDateString() == shortDateString);
Run Code Online (Sandbox Code Playgroud)
但我得到错误:
System.Data.Entity.dll中出现"System.NotSupportedException"类型的异常,但未在用户代码中处理
附加信息:LINQ to Entities无法识别方法'System.String ToShortDateString()'方法,并且此方法无法转换为存储表达式.
考虑到我确实需要使用,我该怎么办ToShortDateString()?
谢谢.
我有一个基本模型类NotificationBase和两个派生模型,GeneralNotification和ReleaseNotification.
public class NotificationBase
{
public int Id { get; set; }
[Required]
[StringLength(50, ErrorMessage="Title must not exceed 50 characters.")]
public string Title { get; set; }
[Required(ErrorMessage="Type is required.")]
public int TypeId { get; set; }
[Required(ErrorMessage="Importance is required.")]
public int ImportanceId { get; set; }
public DateTime Created {get; set; }
[Required(ErrorMessage="Start date is required.")]
public DateTime StartDate { get; set; }
[Required(ErrorMessage="End date is required")]
public DateTime EndDate { get; set; }
[AllowHtml]
[Required(ErrorMessage="Details are required")]
public …Run Code Online (Sandbox Code Playgroud) 我需要知道周数的第一天和最后一天的日期.
我得到一个开始日期和结束日期,代表给定年份中选定周的第一天和最后一天.然后我需要获取上一年同一周的开始日期和结束日期,以对某些数据进行图形比较.
我设法根据给定的开始日期和结束日期获得周数.现在我需要获取前一年同一周的第一天和最后一天的日期.我怎么能最快地做到这一点?
编辑:这是我得到周数的方式:
private int GetWeekNumber(DateTime date)
{
GregorianCalendar calendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
return calendar.GetWeekOfYear(date, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
}
Run Code Online (Sandbox Code Playgroud) 我有以下Javascript正则表达式:
var regex = '/^' + name + '/';
var s ='';
s = this.innerHTML.toString().toLowerCase().match(regex);
if (s != null){
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
此正则表达式无法正常工作,s永远不会设置(s = null总是)有什么想法吗?
我对数据表相当陌生,我想知道是否有一种方法可以将数据异步加载到数据表插件中,以便在创建整个 HTML 表之前呈现数据,如以下帖子所述:
实际上,我需要在有足够的数据来渲染表格时立即创建表格,而不是等待渲染所有表格元素。我的数据表插件来源是一个预渲染的 HTML 表。我在网上找到了一些样品,但我无法制作太多。
这是我发现的:
https://datatables.net/release-datatables/examples/server_side/defer_loading.html
https://datatables.net/release-datatables/examples/server_side/pipeline.html
https://datatables.net/release-datatables/examples/server_side/pipeline.html
我找不到提到的“scripts/server_processing.php”文件(抛出“文件未找到异常”)。这实际上是我必须自己编写的脚本吗?如果是这样,有人可以分享一个示例吗,因为我是 PHP 的新手。
任何示例或相关链接表示赞赏。谢谢
我是新手,所以忍受我; 我正在使用jQuery datatables插件,我需要选择一行并更改所选行的颜色.我从数据表中遵循了这个例子,但它对我不起作用.
这是我初始化表格的方式:
var oTable = $("#rolesTable").dataTable({
// "bJQueryUI": true,
"iDisplayLength": 25,
"aoColumns": [
null,
{"sType": "role"},
null,
null
],
"aaSorting": [[1, "desc"], [0, "asc"]]
});
Run Code Online (Sandbox Code Playgroud)
这是click事件和CSS类的代码:
<style>
.row_selected tr {
background-color: black;
}
</style>
Run Code Online (Sandbox Code Playgroud)
$("#rolesTable tbody tr").click(function (event) {
$(oTable.fnSettings().aoData).each(function () {
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
Run Code Online (Sandbox Code Playgroud)
对不起,我添加了点击处理程序
我需要评估 JavaScript 函数中的 razor 变量。鉴于以下代码:
@{var unseenNotificationsExist = false;}
@foreach(var notification in viewModel)
{
if (notification.WasSeen == false)
{
unseenNotificationsExist = true;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
我需要unseenNotificationsExist像这样在 JavaScript 中评估变量:
if(@unseenNotificationsExist == true)
$('#unseenNotifCount').addClass('notifNotSeen');
Run Code Online (Sandbox Code Playgroud)
但是,当我调试 JavaScript 代码时,我得到以下信息:
if(True == true)
Run Code Online (Sandbox Code Playgroud)
而且我收到以下错误:
未捕获的 ReferenceError True 未定义
我想知道是否可以为一个用户同时建立多个 SFTP 连接。我构建了一个服务来下载/上传文件到特定的 SFTP 服务器。该服务有 4 个正在运行的任务,所有任务都与这个 SFTP 服务器打交道,并且都使用相同的凭据。为了防止任何可能的问题,我创建了一个单例类来上传/下载文件。我试图将任务分成不同的独立 Windows 服务,以防止在其中一个任务失败时停止所有任务(由于超时,确实会发生这种情况)。这样做会有什么问题吗?
太感谢了。
尝试在视图(MVC 应用程序)中使用 Html.EditorForModel 帮助程序时收到上述错误。这是视图的代码:
@model CodeFirst.Models.Person
@{
ViewBag.Title = "CreatePerson";
}
<h2>CreatePerson</h2>
@using (Html.BeginForm())
{
<fieldset>
<legend>Create person entry</legend>
@Html.EditorForModel()
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
Run Code Online (Sandbox Code Playgroud)
我试图使用对象类型的编辑器模板。这是模板
@inherits System.Web.Mvc.WebViewPage
@if (Model == null)
<span>@ViewData.ModelMetadata.NullDisplayText</span>
else
{
<table cellpadding="0" cellspacing="0" class="editor-table">
@foreach (var prop in ViewData
.ModelMetadata
.Properties
.Where(pm => pm.ShowForDisplay && !ViewData.TemplateInfo.Visited(pm)))
{
<tr>
<td>
<div class="editor-label">
@prop.GetDisplayName()
</div>
</td>
<td width="10px">@(prop.IsRequired ? "*" : "") </td>
<td>
<div class="editor-field">
<span>@Html.Editor(prop.PropertyName)</span>
<span>@Html.ValidationMessage(prop.PropertyName, "*")</span>
</div>
</td>
</tr>
}
</table> …Run Code Online (Sandbox Code Playgroud) 我在 keyup 事件上使用以下函数重定向到另一个 javascript 函数。问题是它似乎没有触发,尽管它确实将函数绑定到文本框。
$(document).ready(function () {
EnablePickTargetButton();
//clear contents; use a delay because tinyMCE editor isn't always fully loaded on document.ready
var t = setTimeout(function () {
if (typeof textEditorForCreate != 'undefined' && tinymce.editors.length > 0)
tinyMCE.activeEditor.setContent('');
}, 300);
var txtSearchUser = $('#txtSearchUser');
if(typeof txtSearchUser != 'undefined')
{
$('#txtSearchUser').keyup(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
searchUser();
}
else
alert('cucu');
});
}
});
Run Code Online (Sandbox Code Playgroud)
甚至没有出现警报。检查 html,我可以看到它没有将 onkeyup 添加到文本框;文本框位于窗体上 div 中托管的弹出窗口中;但是在 document.ready 上它运行该函数没有错误。
javascript ×5
asp.net-mvc ×4
c# ×4
datatables ×2
razor ×2
.net ×1
date ×1
jquery ×1
linq ×1
regex ×1