小编Nic*_*ray的帖子

如何淡化循环库背景图像

我希望旋转div的背景图像,我认为这使我不能使用优秀的jQuery Cycle Plugin.

下面的代码是我到目前为止,但它没有按照我的意愿行事,这是:

  • 淡出第一张图片
  • 在没有显示图像的情况下用第二张图像交换图像 - (在第二张图像中失败此淡入淡出)
  • 并重复到无限......以及更远.

<script type='text/javascript' src='http://code.jquery.com/jquery-1.5.2.js'></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script> 
<link rel="stylesheet" type="text/css" href="/css/normalize.css"> 
<link rel="stylesheet" type="text/css" href="/css/result-light.css"> 

<style type='text/css'> 
#mydiv {

        width: 100%;
        height: 365px;
        margin-left: auto;
        margin-right: auto;
        position: relative;
        display: block;
        background: url(HP_jQuery1.jpg) center top no-repeat;
}
</style>

<script type='text/javascript'> 
$(window).load(function(){
var firstTime = true;
var arr = ["url(HP_jQuery2.jpg)", "url(HP_jQuery3.jpg)"];
    (function recurse(counter) {
        var bgImage = arr[counter];
        if (firstTime == false) {
            $("#mydiv").fadeOut("slow");
            $('#mydiv').css('background-image', bgImage);
            $("#mydiv").fadeIn("slow");
        } else {
            firstTime = false; …
Run Code Online (Sandbox Code Playgroud)

css jquery

8
推荐指数
1
解决办法
8594
查看次数

Asp.Net MVC和Web服务

我有一个现有的Asp.Net MVC网站,我也想从同一个域提供一个Web服务.

在此场景中创建Web服务的最佳方法是什么?

我是否会添加到此项目或...?

asp.net asp.net-mvc web-services

7
推荐指数
1
解决办法
3839
查看次数

Json.Net序列化对象丢失其Id值

我正在使用Json.Net来序列化和反序列化一个对象.

我遇到一个问题,其中反序列化对象recordPosted的Id为零.

序列化记录将包含Id为180

JsonSerializerSettings jsSettings = new JsonSerializerSettings();
jsSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

var recordAsJson = JsonConvert.SerializeObject(recordToUpdate, 
                                Formatting.None, jsSettings);
//recordAsJson = {"Id":180,....


 var recordPosted = JsonConvert.DeserializeObject<record>(recordAsJson);
 //recordPosted = Id : 0
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

编辑

public virtual int Id { get; private set; }
Run Code Online (Sandbox Code Playgroud)

c# json json.net

7
推荐指数
1
解决办法
2766
查看次数

如何使用依赖注入执行通用存储库

我已经设置了我的通用存储库,如下所示:

public interface IRepository<T> : IDisposable where T : Entity
{
    T GetById(int id);
}

public abstract class Repository<T> : IRepository<T> where T : Entity
{
    protected readonly SqlDbContext _context = new SqlDbContext();

    public T GetById(int id)
    {
        return _context.Set<T>().Find(id);
    }   
}
Run Code Online (Sandbox Code Playgroud)

为了在我的MVC应用程序中启用依赖项注入,我还创建了一个Product接口,因为签名不同.其他存储库也是如此.

public interface IProductRepository : IRepository<Product>
{
    IEnumerable<Product> GetDiscountedProducts();
}
Run Code Online (Sandbox Code Playgroud)

和实现(注意继承)

public class ProductRepository : Repository<Product>, IProductRepository
{
    public IEnumerable<Product> GetDiscountedProducts()
    {
        return _context.Set<Product>().Where(x=>x)...
    }           
}
Run Code Online (Sandbox Code Playgroud)

最后,使用unity将存储库注入MVC​​控制器

public HomeController(IProductRepository repository)
{
}
Run Code Online (Sandbox Code Playgroud)

这只是我还是这个继承链在这里有点乱?有没有办法改进这个设计?

c# asp.net-mvc repository-pattern

7
推荐指数
1
解决办法
2369
查看次数

Firefox在ASP.Net MVC中出现压缩过滤器属性问题

在ASP.Net MVC 2中我使用以下压缩过滤器,在Chrome中它工作正常,但在Firefox 3.3.6中它返回奇怪的字符.

public class CompressAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        //get request and response 
        var request = filterContext.HttpContext.Request;
        var response = filterContext.HttpContext.Response;

        //get requested encoding 
        if (!string.IsNullOrEmpty(request.Headers["Accept-Encoding"]))
        {
            string enc = request.Headers["Accept-Encoding"].ToUpperInvariant();

            //preferred: gzip or wildcard 
            if (enc.Contains("GZIP") || enc.Contains("*"))
            {
                response.AppendHeader("Content-encoding", "gzip");
                response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
            }

            //deflate 
            else if (enc.Contains("DEFLATE"))
            {
                response.AppendHeader("Content-encoding", "deflate");
                response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
            }
        }
        base.OnActionExecuting(filterContext);
    }
}
Run Code Online (Sandbox Code Playgroud)

以下是Firefox显示的字符示例:

I?%&/m?{J?J??t??$ @ iG#)* eVe] f @ …

compression asp.net-mvc firefox

6
推荐指数
1
解决办法
1097
查看次数

使用HtmlAgilityPack解析HTML页面以按类选择Div

我正在使用C#和HtmlAgilityPack,我可以选择id为foo的div

var foos = from foo in htmlDoc.DocumentNode.Descendants("div")
           where foo.Id == "foo" 
           select foo;
Run Code Online (Sandbox Code Playgroud)

但是如何用一类条选择div呢?

html c# html-agility-pack

5
推荐指数
1
解决办法
1万
查看次数

学习WCF中的教程时,EndpointNotFoundException

我正在阅读学习WCF一书和第一个教程实验室HelloIndigo我收到以下错误.

无法连接到http:// localhost:8000/HelloIndigo/HelloIndigoService.TCP错误代码10061:无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8000.

它出现在客户端项目中的字符串s = proxy.HelloIndigo();

EndpointAddress ep = new EndpointAddress("http://localhost:8000/HelloIndigo/HelloIndigoService");

IHelloIndigoService proxy = ChannelFactory<IHelloIndigoService>.
            CreateChannel(new BasicHttpBinding(), ep);
string s = proxy.HelloIndigo();
Console.WriteLine(s);
Console.WriteLine("Press <ENTER> to terminate Client");
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

我已经深入搜索了这个,但我不是更明智的.

任何人都可以解释这个问题以及如何补救?

c# wcf

5
推荐指数
1
解决办法
1472
查看次数

Asp.Net MVC UNITOfWork和MySQL和睡眠连接

我有一个基于以下架构的MVC Web应用程序

Asp.Net MVC2,Ninject,Fluent NHibernate,MySQL使用单位工作模式.

与MySQL的每个连接都会生成一个睡眠连接,可以将其视为SHOW PROCESSLIST查询结果中的一个条目.

最终,这将产生足够的连接来执行应用程序池限制并使Web应用程序崩溃.

我怀疑连接没有正确处理.

如果是这种情况,应该如何发生?

这是我正在使用的代码的快照:

public class UnitOfWork : IUnitOfWork
{
    private readonly ISessionFactory _sessionFactory;
    private readonly ITransaction _transaction;
    public ISession Session { get; private set; }

    public UnitOfWork(ISessionFactory sessionFactory)
    {
        _sessionFactory = sessionFactory;
        Session = _sessionFactory.OpenSession();
        Session.FlushMode = FlushMode.Auto;
        _transaction = Session.BeginTransaction(IsolationLevel.ReadCommitted);
    }

    public void Dispose()
    {
        if (Session != null)
        {
            if (Session.IsOpen)
            {
                Session.Close();
                Session = null;
            }
        }
    }

    public void Commit()
    {
        if (!_transaction.IsActive)
        {
            throw new InvalidOperationException("No active …
Run Code Online (Sandbox Code Playgroud)

mysql asp.net-mvc ninject unit-of-work fluent-nhibernate

5
推荐指数
1
解决办法
929
查看次数

根据数据库表值创建标签或其他控件

我想根据数据库列值创建一个标签或文本框.例如:我有一个数据库表列值休闲假,医疗假,年假等.我想为上面的列创建动态标签和相应的文本框值.

我想要像这样的控件..

         Casual Leave :  Textbox1
         Medical Leave:  Textbox2
         Annul Leave  :  Textbox3
         etc based on table value
Run Code Online (Sandbox Code Playgroud)

我所做的?我不能这样做.请帮我...

c# asp.net c#-4.0

5
推荐指数
1
解决办法
1483
查看次数

使用Javascript将文件扩展名下载Html5 canvas元素作为图像

我希望能够使用Javascript将文件扩展名下载Html5 canvas元素作为图像.

CanvasToImage库似乎并没有能够做到这一点.

到目前为止,这是我的代码,你可以在这个JsFiddle看到.

<div id="canvas_container">
</div>
<p>
<a href='#' id="create_image">create</a> 
<a href="#" id="download_image">download</a>
</p>




$("#create_image").click(function() {
var cnvs = createSmileyOnCanvas();
$('#canvas_container').append(cnvs);
});


$("#download_image").click(function() {    
var img = $('#smiley_canvas').toDataURL("image/png");
var uriContent = "data:application/octet-stream," + encodeURIComponent(img);
window.open(uriContent, 'download smiley image');
});



function createSmileyOnCanvas() {
var canvas = document.createElement('canvas');      
canvas.id = 'smiley_canvas';    
var ctx = canvas.getContext('2d');        

// Draw shapes
ctx.beginPath();
ctx.arc(75,75,50,0,Math.PI*2,true); // Outer circle
ctx.moveTo(110,75);
ctx.arc(75,75,35,0,Math.PI,false);   // Mouth
ctx.moveTo(65,65);
ctx.arc(60,65,5,0,Math.PI*2,true);  // Left eye
ctx.moveTo(95,65);
ctx.arc(90,65,5,0,Math.PI*2,true);  // Right eye …
Run Code Online (Sandbox Code Playgroud)

javascript jquery html5 canvas

5
推荐指数
2
解决办法
1万
查看次数