我有一个控制器:
private readonly ILogger _logger;
private readonly IRepository _repository;
public HomeController(ILogger logger, IRepository repository)
{
_logger = logger;
_repository = repository;
}
Run Code Online (Sandbox Code Playgroud)
这是存储库:
public class EfRepository : IRepository
{
// ...methods for add, delete, update entities
// ....
public void Dispose()
{
if (this._context != null)
{
this._context.SaveChanges();
(this._context as IDisposable).Dispose();
this._context = null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
最后,IoC中的注册类型:
_builder.RegisterType<Logger>().As<ILogger>();
_builder.RegisterType<EfRepository>().As<IRepository>().WithParameter("context", new PcpContext());
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我收到此错误:
由于已经处理了DbContext,因此无法完成操作.
我试着改变注册EfRepository,如下所示:
_builder.RegisterType<EfRepository>()
.As<IRepository>()
.WithParameter("context", new PcpContext()).InstancePerLifetimeScope();
Run Code Online (Sandbox Code Playgroud)
在这种情况下,第一个请求完成,但在尝试打开其他页面时,我再次收到错误.问题出在哪儿?
在我的网站上执行某些操作后,用户可以下载文件.首先,我问用户:"你想下载文件吗?" 这是使用fancybox创建的模态对话框.有按钮:是和否.当用户点击"是"时,我想在浏览器中打开新标签并显示标准保存文件对话框.我有这个代码:
$(document).on('click', '#agentAcceptSave', function () {
alert(1);
window.open = '/ticket?orderId=' + $('#agentOrderId').val();
}
Run Code Online (Sandbox Code Playgroud)
但是,新标签未打开且网址未调用,但显示警报.哪里出错?
我有一本字典:Dictionary<int,int>.我想得到新词典,其中原始词典的键表示为List<int>.这就是我的意思:
var prices = new Dictionary<int,int>();
Run Code Online (Sandbox Code Playgroud)
将prices包含以下数据:
1 100
2 200
3 100
4 300
Run Code Online (Sandbox Code Playgroud)
我想得到IList<Dictionary<int,List<int>>>:
int List<int>
100 1,3
200 2
300 4
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
为了渲染SVG我正在使用jQuery SVG插件.而且,现在我想为每个路径和多边形添加文本.在jsFiddle上,您可以看到插件生成的标记.
为了创建文本,我编写了以下代码:
var svgg = $("#rsr").svg('get');
var texts = svgg.createText();
svgg.textpath($("#Layer_x0020_1"),id, texts.string('We go ').
span('up', { dy: -30, fill: 'red' }).span(',', { dy: 30 }).
string(' then we go down, then up again'));
Run Code Online (Sandbox Code Playgroud)
在jsFiddle的代码中,您可以看到textpath标记存在,但它不可见.如何将文本添加到每个路径的中心?
谢谢.
我有一个包含以下列的表:
ID Name
1 test1
2 test2
Run Code Online (Sandbox Code Playgroud)
现在我添加了新专栏IsConfirmed.此列包含null所有行.
ID Name IsConfirmed
1 test1 null
2 test2 null
Run Code Online (Sandbox Code Playgroud)
如何使用T-SQL false将IsConfirmed列设置为表中的所有行?
谢谢
我有以下字符串模式:1:2,2:3.
这就像一个字符串中的数组:
第一个元素是:1:2
第二个元素是:2:3
我想解析它并创建一个字典:
1,2 // 0 element in Dictionary
2,3 // 1 element in Dictionary
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
Dictionary<int,int> placesTypes = new Dictionary<int, int>();
foreach (var place in places.Split(','))
{
var keyValuePair = place.Split(':');
placesTypes.Add(int.Parse(keyValuePair[0]), int.Parse(keyValuePair[1]));
}
Run Code Online (Sandbox Code Playgroud)
有最好的方法吗?
谢谢.
我正在使用Raphael与SVG合作.而且,我想在每条路径中添加文字.我怎样才能做到这一点?这是我在jsfiddle上的代码.
谢谢
我有以下表格:
@using (Ajax.BeginForm("DoComment", "Publication", new { id = Model.Publication.OID, parentId = Model.OID }, new AjaxOptions
{
OnSuccess = "publishCommentSuccess"
}))
{
//some code
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能parentId进入publishCommentSuccess功能?
function publishCommentSuccess (json) {
if (!json.Result)
showAuthBox();
else
alert(json.Message);
};
Run Code Online (Sandbox Code Playgroud)
谢谢.
例如,我们有两个集合:
coll1 = {1,2,3,4,5}
coll2 = {3,4,5,6,7,8,9}
Run Code Online (Sandbox Code Playgroud)
如何在两个集合中找到包含元素的数量(最佳性能)?
例如,上面的结果必须相同3.
谢谢,
我有两个应用程序.第一个是WCF服务,第二个是asp.net MVC 3应用程序.
在WCF应用程序中,我有一个界面:
[ServiceContract]
public interface IService1
{
[OperationContract]
string HelloWorld(string personName);
}
Run Code Online (Sandbox Code Playgroud)
一节课:
public class Service1 : IService1
{
public string HelloWorld(string personName)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize("Hello " + personName);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,在asp.net mvc应用程序中,我想通过Ajax调用此方法:
<script type="text/javascript">
var personName = "John";
var dataIn = '{' + '"input":"' + personName + '"}';
$.ajax({
url: "http://localhost:7215/Service1.svc/HelloWorld",
type: "POST",
contentType: "application/json; charset=utf-8",
data: dataIn,
dataType: "json",
success: function (data) {
var object = JSON.parse(data.d);
if (object.Error == '') …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×3
c# ×3
ajax ×2
javascript ×2
jquery ×2
linq ×2
.net ×1
autofac ×1
dictionary ×1
forms ×1
grouping ×1
jquery-svg ×1
raphael ×1
sql-server ×1
svg ×1
t-sql ×1
wcf ×1