我有要求插入texttarea中输入的文本,当文本在文本框中更改。我使用jquery更改函数来完成此操作。我得到控制器从ajax触发actionmethod,但是,来自视图的文本没有传递给模型。 (使用的代码:MVC4/entity dbfirst /剃刀) 这是我的详细代码。传递值从视图到控制器模型在httppost从ajaxcall不起作用
控制器:
public ActionResult Index()
{
return View();
}
public ActionResult Dailynotes()
{
return View();
}
//I’m getting this code hit from ajaxcall, but dashboard model is null????????
tblDailyNotes note = new tblDailyNotes();
[HttpPost]
public ActionResult Dailynotes(DashboardViewModel model)
{
int noteid = 0;
model.Dailynotes = note.Note;
_scheduler.InsertDailynote(note);//this is the sp to insert the note
return View();
}
Index.cshtml:
<div id="content">
@(Html.Kendo().TabStrip()
.Name("tabstrip")
.Items(tabstrip =>
{
tabstrip.Add().Text("Daily Notes")
.Selected(true)
.LoadContentFrom("Dailynotes", "Scheduler");
})
)
</div>
<div>
@{Html.RenderAction("Dailynotes", "Scheduler");}
</div>
Dailynotes.cshtml:
@model proj.Models.DashboardViewModel
@Html.TextAreaFor(model => model.Dailynotes, new {@class="k-textbox",id="dailynotes"})
<script>
$("#dailynotes").change(function() {
alert("Changed");
debugger;
$.ajax({
cache: true,
type: "POST",
url: window.location.pathname + "Scheduler/Dailynotes",
success: function (data) {
},
error: function (xhr, ajaxOptions, thrownError) {
},
complete: function() { }
});
});
个
Dashboardviewmodel.cs
public class DashboardViewModel
{
public string Dailynotes { get; set; }
public string Weeklynotes { get; set; }
}
我得到了AJAX调用后行动,但dashboardmodel不回我在模型文本框中输入的文本。
请帮助..
编辑1: /不工作
$("#dailynotes").change(function() {
alert("Changed");
var dailynotes = $('#dailynotes').val();
debugger;
$.ajax({
url: window.location.pathname + 'Scheduler/Dailynotes',
type: 'POST',
//data: $('form').serialize(),
data:{ model:dailynotes }
})
.success(function (result) {
alert("note saved successfully");
});
});
尝试更改这样的网址:'url:“@ Url.Action(”Action“,”Controller“,new {area =”AreaName“})”,' –
尝试更改类型:'POST' –