我已经使用了两天了,搜索和尝试。但我仍然无法实现我的目标:
将 Jquery 对话框滑块值传递给控制器。
前端:
@model TheMoodApp.Models.tbl_user
@{
ViewBag.Title = "ControlPanel";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>@Html.DisplayFor(u=>u.Forename)'s Control Panel</h2>
@* Adding header stuff for control panel *@
@section DialogControlPanel{
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"/>
<script src="https://raw.github.com/brandonaaron/bgiframe/master/jquery.bgiframe.js"/>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"/>
<script src="~/Scripts/MoodAppScripts.js"/>
<link href="~/Content/MoodApp.css" rel="stylesheet" />
}
@*The dialog for set initial mood*@
<div id="dialog-modal" title="Hi @Html.DisplayFor(u=>u.Forename)<br/>How do U feel 2Day?">
<header id="InitialMoodHeader">
<p>Set UR Mood
<input type="text" id="DisplayMood" readonly="readonly"/>
</p>
</header>
<section id="InitialMoodSlider">
<div id="MoodSlider"></div>
</section>
</div>
Javascript文件:
$(document).ready(
function () {
$("#dialog-modal").dialog({
height: 140,
modal: true,
buttons: {
"This is my Mood": function () {
$.ajax({
url: '@Url.Action("User", "CheckInMood")',
data: JSON.stringify({ mood: $("#DisplayMood").val() }),
type: 'POST',
contentType: 'application/json; charset=utf-8',
});
$(this).dialog("close");
}
}
});
$("#MoodSlider").slider({
//TODO: IMPLEMENT JSON TO GET MOOD; ATM FEATURE IS FIXED.
range: "max",
min: 0,//scales minimum
max: 3,//scales maximum
value: 2,//default value
slide: function (event, ui) {
$("#DisplayMood").val(ui.value);//get value from slider and display it
}
});
$("#DisplayMood").val(
$("#MoodSlider").slider("value")
);//set input value from slider
});
控制器:
[HttpPost]
public JsonResult CheckInMood(string mood)
{
//current user checks in with current mood
uint i = Convert.ToUInt16(mood);
return Json(View());
}
有人可以帮助我,让它发挥作用,并向我解释我做错了什么吗?
提前致谢
//borb