我试图填充GridView
使用Entity Frameworkm但每次我收到以下错误:
"对象'COSIS_DAL.MemberLoan'上的属性访问器'LoanProduct'引发了以下异常:ObjectContext实例已被释放,不能再用于需要连接的操作."
我的代码是:
public List<MemberLoan> GetAllMembersForLoan(string keyword)
{
using (CosisEntities db = new CosisEntities())
{
IQueryable<MemberLoan> query = db.MemberLoans.OrderByDescending(m => m.LoanDate);
if (!string.IsNullOrEmpty(keyword))
{
keyword = keyword.ToLower();
query = query.Where(m =>
m.LoanProviderCode.Contains(keyword)
|| m.MemNo.Contains(keyword)
|| (!string.IsNullOrEmpty(m.LoanProduct.LoanProductName) && m.LoanProduct.LoanProductName.ToLower().Contains(keyword))
|| m.Membership.MemName.Contains(keyword)
|| m.GeneralMasterInformation.Description.Contains(keyword)
);
}
return query.ToList();
}
}
protected void btnSearch_Click(object sender, ImageClickEventArgs e)
{
string keyword = txtKeyword.Text.ToLower();
LoanController c = new LoanController();
List<COSIS_DAL.MemberLoan> list = new List<COSIS_DAL.MemberLoan>();
list = c.GetAllMembersForLoan(keyword);
if (list.Count <= 0)
{ …
Run Code Online (Sandbox Code Playgroud) 使用iframe打开Twitter Bootstrap Modal的页面:
<div id="iframeModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="btn btn-danger pull-right" data-dismiss="modal" aria-hidden="true">Close</button>
<div class="clearfix"></div>
</div>
<div class="modal-body">
<iframe src="iframe-modal.html"></iframe>
</div>
<div class="modal-footer">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
而我正在寻找一种从iframe内部关闭此模态的方法.防爆.单击内部的链接iframe-modal.html
以关闭模态.我尝试了什么,但没有成功:
$('#iframeModal', window.parent.document).modal('hide');
$('#iframeModal', top.document).modal('hide');
$('#iframeModal').modal('hide');
Run Code Online (Sandbox Code Playgroud) 我已经搜索了一段时间并且一直在努力寻找这个,我正在尝试生成几个随机的,唯一的数字是C#.我正在使用System.Random
,我正在使用DateTime.Now.Ticks
种子:
public Random a = new Random(DateTime.Now.Ticks.GetHashCode());
private void NewNumber()
{
MyNumber = a.Next(0, 10);
}
Run Code Online (Sandbox Code Playgroud)
我NewNumber()
经常打电话,但问题是我经常会重复数字.有些人建议因为我每次都是随机声明它,它不会产生随机数,所以我把声明放在我的函数之外.有什么建议或比使用更好的方法System.Random
?谢谢
我使用以下代码使用Gmail帐户从我的Web应用程序发送邮件.我的问题是,我可以将发件人地址更改为原始发件人(gmail)地址以外的其他地址吗?我的代码如下:
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("sample@gmail.com", "*******");
Run Code Online (Sandbox Code Playgroud)
无论我做什么都没用,因为我总是收到邮件sample@gmail.com
.是否有可能改变它?
我已经改为
mail.From = new System.Net.Mail.MailAddress("sample@yahoo.com");
但是我收到了来自发件人地址的邮件,sample@gmail.com
而不是来自新的"发件人"地址.我认为gmail smtp用原始凭证覆盖起始地址.
我有异步回调,它被传递到Timer(来自System.Threading)构造函数:
private async Task HandleTimerCallback(object state)
{
if (timer == null) return;
if (asynTaskCallback != null)
{
await HandleAsyncTaskTimerCallback(state);
}
else
{
HandleSyncTimerCallback(state);
}
}
Run Code Online (Sandbox Code Playgroud)
和计时器:
timer = new Timer(async o => await HandleTimerCallback(o), state, CommonConstants.InfiniteTimespan,
CommonConstants.InfiniteTimespan);
Run Code Online (Sandbox Code Playgroud)
有没有办法o
在lambda中省略那个参数?非同步的原因我可以将我handler
作为委托传递
timer = new Timer(HandleTimerCallback, state, CommonConstants.InfiniteTimespan,
CommonConstants.InfiniteTimespan);
Run Code Online (Sandbox Code Playgroud) 在图片中,选项的宽度大于选择框.我想将这些选项的宽度设置为与选择框相同,对于那些较大的选项,将text-overflow设置为省略号.任何帮助,将不胜感激.
这是我尝试过的:
HTML
<select>
<option>Select your University</option>
<option>Bangladesh University of Engineering and Technology</option>
<option>Mawlana Bhashani Science and Technology University</option>
</select>
Run Code Online (Sandbox Code Playgroud)
CSS
select, option {
width: 250px;
}
option {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
Run Code Online (Sandbox Code Playgroud)
我有一个常量类.我有一些字符串,可以与其中一个常量的名称相同或不同.
所以带常数的类ConstClass
有一些public const
像const1, const2, const3...
public static class ConstClass
{
public const string Const1 = "Const1";
public const string Const2 = "Const2";
public const string Const3 = "Const3";
}
Run Code Online (Sandbox Code Playgroud)
要检查类是否const
按名称包含,我已尝试过下一步:
var field = (typeof (ConstClass)).GetField(customStr);
if (field != null){
return field.GetValue(obj) // obj doesn't exists for me
}
Run Code Online (Sandbox Code Playgroud)
不知道它是否真的是正确的方法,但现在我不知道如何获取值,导致.GetValue
方法需要obj类型ConstClass
(ConstClass是静态的)
<select id="divRatings" class="selectpicker" multiple title='Choose one of the following...' data-size="5" data-selected-text-format="count>2">
<option value="All" selected="selected">All Ratings</option>
<option value="EC">EC (Early Childhood)</option>
<option value="E">E (Everyone)</option>
<option value="E10+">E10+ (Everyone 10+)</option>
<option value="T">T (Teen)</option>
<option value="M">M (Mature)</option>
<option value="AO">AO (Adults Only)</option>
</select>
Run Code Online (Sandbox Code Playgroud)
在上面的html中有值的选项All
.如果选择了该选项,我想选择所有项目,如果取消选择此选项,则取消选择全部.
我认为做起来很简单,但我无法理解为什么没有发生 $('#divRatings').change(function(){//some logic});
我选择/取消选择项目的功能:
function toggleSelectAll(control) {
if (control.val().indexOf("All,") > -1) {
control.selectpicker('selectAll');
} else {
control.selectpicker('deselectAll');
}
}
Run Code Online (Sandbox Code Playgroud)
我的中有以下内容appSetting.json
;
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"MailServiceSettings": {
"SmtpServer": "<server>",
"ToAddresses": [
"email@domain.com",
"email2@domain.com"
],
"UserName": "username",
"Password": "password"
}
}
Run Code Online (Sandbox Code Playgroud)
而appSettings.Development.json
我也有了微妙的变化;
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"MailServiceSettings": {
"SmtpServer": "<server>",
"ToAddresses": [
"development@domain.com"
],
"UserName": "username",
"Password": "password"
}
}
Run Code Online (Sandbox Code Playgroud)
这样我就可以在本地主机中发送邮件发件人设置文本,而无需轰炸实时邮箱。
但是,当我在调试中运行时,设置appSettings.json
将被注入而不是appSettings.Development.json
.
我的Program.cs
是使用默认的WebHostBuilder
;
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args)
.Build().Run(); …
Run Code Online (Sandbox Code Playgroud) c# ×7
asp.net ×2
jquery ×2
.net ×1
asp.net-core ×1
async-await ×1
asynchronous ×1
const ×1
css ×1
field ×1
gmail ×1
html-select ×1
javascript ×1
lambda ×1
nlog ×1
parent-child ×1
random ×1
smtp ×1
timer ×1
unique ×1