评级asp.net mvc4实体框架 [英] Rating in asp.net mvc4 entity framework

查看:226
本文介绍了评级asp.net mvc4实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图评级与实体框架asp.net mvc4,我试图在这个CSHTML code,但它不能正常工作,请大家帮我实现这一目标。其工作,而我在正常的浏览器正在运行,但同时融入asp.net mvc4

I am trying rating in asp.net mvc4 with entity framework, I have tried this code in cshtml but it is not working, please help me to achieve this. Its working while i am running in normal browser but it is not working while integrating into the asp.net mvc4

{
  <h2>rating</h2>
  <form method="post" id="signin" action="@Url.Action("rating", "Rating")">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

      <script type="text/javascript" src="D:\My Programs\FSLIndiaLatest\FSLIndiaLatest\Scripts\jquery.js"></script>
      <script type="text/javascript" src="D:\My Programs\FSLIndiaLatest\FSLIndiaLatest\Scripts\rating.js"></script>
      <link rel="stylesheet" type="text/css" href="D:\My Programs\FSLIndiaLatest\FSLIndiaLatest\Styles\rating.css" />
      <script type="text/javascript">
         $(function () {
            $('.rating').rating();
            $('.ratingEvent').rating({ rateEnd: function (v) { $('#result').text(v); } });
         });
      </script>
      <input type="text" class="ratingEvent rating9" value="5" />
      <div><b id="result">5</b> start(s)</div>
      <p>&nbsp;</p>
  </form>
}

code为rating.js
{

code for rating.js {

(function ($)
{
    $.fn.rating = function (options)
    {
        var settings = $.extend(
            {
                rateEnd: function (value) { }
            }, options);

        function setRating(e, ul)
        {
            var i = parseInt(e.val());
            if (!i) { i = 0; }

            ul.find('a').removeAttr('class');
            ul.find('a:lt(' + i + ')').attr('class', 'full');
        }

        this.each(function ()
        {
            var e = $(this);
            var c = parseInt(e.attr("class").match(/rating\d+/)[0].replace('rating', ''));

            var ul = $('<ul class="rating"></ul>').insertAfter(e).width(c * 20 + 'px');

            if (c > 0)
            {
                for (k = 0; k < c; k++)
                {
                    ul.append('<li><a href="javascript:void(0);" title="' + (k + 1) + '">' + (k + 1) + '</a></li>')
                }
            }

            if (e.prop('readonly'))
            {
                var i = parseInt(e.val());

                if (!i) { i = 0; }

                ul.find('a').attr('title', i + ' / ' + c);
            }
            else
            {
                ul.find('a').each(function (index, link)
                {
                    var link = $(link);

                    link.hover(function ()
                    {
                        ul.find('a').removeAttr('class');
                        ul.find('a:lt(' + (index + 1) + ')').attr('class', 'hover');

                    }, function ()
                    {
                        setRating(e, ul);
                    });

                    link.click(function ()
                    {
                        e.val(index + 1);

                        setRating(e, ul);

                        settings.rateEnd(index + 1);
                    });
                });
            }

            setRating(e, ul);

            e.hide();
        });

        return this;
    }

})(jQuery);

}

code为rating.css

code for rating.css

{

.rating { height: 20px; padding:0px; margin:0px; }
.rating li { list-style: none; float: left; width: 20px; height: 20px; padding:0px; margin:0px;}
.rating li a { display: block; width: 20px; height: 20px; padding:0px; margin:0px; overflow: hidden; text-indent: -100px; background-image: url(D:\My Programs\FSLIndiaLatest\FSLIndiaLatest\Images\rating.png); background-repeat: no-repeat; text-decoration:none; }
.rating li a:hover { background-color: transparent; text-decoration: none; }
.rating li .hover { background-position: 0px -20px; }
.rating li .full { background-position: 0px -40px; }

}

推荐答案

我假设你用剃刀发动机的工作。如果是这样,不这样做:

I assume you're working with razor engine. If so, don't do this:

<script type="text/javascript" src="D:\My Programs\FSLIndiaLatest\FSLIndiaLatest\Scripts\jquery.js"></script>

相反,这样做:

<script type="text/javascript" src="~/Scripts/jquery.js"></script>

修改

这适用于所有的.js和.css文件由它们的绝对本地路径引用。如果〜/ 功能并不适用于您,请尝试使用相对路径: SRC =/脚本/ jquery.js和

This applies to all your .js and .css files referenced by their absolute local paths. If ~/ feature doesn't work for you, try using relative paths: src="/Scripts/jquery.js"

在HTML中引用的所有文件应包括在您的项目。

All the files referenced in your html should be included in your project.

这是因为你在访问一个简单的本地HTML页面可能在之前已经为你工作。如果HTML页面的服务器上托管的(因为它是,当你运行一个MVC 4应用程序),它不能访问本地文件。

It may have worked for you before because you were accessing a simple local html page. If the html page is hosted on a server (as it is, when you're running an MVC 4 application), it cannot access local files.

这篇关于评级asp.net mvc4实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆