如何在asp.net mvc4中获得评级值?

时间:2014-02-19 04:55:01

标签: asp.net-mvc-4 asp.net-routing

我是新的asp.net mvc4,实体框架工作,我在cshtml文件中设计了评级,请帮我在Controller中获得额定值。提前致谢。 这是我的评级cshtml代码 {

@{
    ViewBag.Title = "Index";
}

<h2>Index rating</h2>

  <h2>rating</h2>
  @*<form method="post" id="signin" action="@Url.Action("rating", "Rating")">*@
  @if (Request.IsAuthenticated)
  { 
      <form method="post" id="signin" action="@Url.Action("rating", "Rating")">
 <p>
 @DateTime.Now
 </p>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <script type="text/javascript" src="~/Scripts/jquery.js"></script>
      <script type="text/javascript" src="~/Scripts/rating.js"></script>
      <link rel="stylesheet" type="text/css" href="~/Styles/rating.css" />
      <script type="text/javascript">
          $(function () {
              $('.rating').rating();
              $('.ratingEvent').rating({ rateEnd: function (v) { $('#result').text(v); } });
          });
      </script>
      <input type="text" class="ratingEvent rating5" @*id="result"*@ value="rating" />
      <div><b id="result">5</b> start(s)</div>
      <p>&nbsp;</p>

  </form>
  }

} 这是我的控制器代码 {

[HttpGet]
        public ActionResult rating(int ratedvalue)
        {
            using (var db = new Project.Models.EntitiesContext())
          {

            var value= new Project.Models.Tbl_Rating();
            var rat = db.Tbl_Rating.FirstOrDefault(u => u.Rating == ratedvalue);
            value.Rating = Convert.ToInt32(rat);

            return View();

        }
    }
}

}

1 个答案:

答案 0 :(得分:0)

试试这个

查看:

 <form method="post" id="signin" action="@Url.Action("rating", "Rating")">
      **YOUR CODE**
  <input type="text" class="ratingEvent rating5" name="rating" value="rating" /> //Add name attribute
  <input type="submit" />         
</form>

控制器:

 public ActionResult rating(FormCollection form)
  {
     int ratedvalue=form["rating"]
  }