Pass values from view to controller model on httppost from ajaxcall not
working
I have the requirement to insert text entered in the textareafor when the
text is changed in the textbox.I used jquery change function to get this
done.I get the controller hit on the actionmethod from ajax but, text from
view is not getting passed to model. (Code used: MVC4 /entity dbfirst/
razor) Here is my detailed code.
Controller:
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; }
}
I get the ajax calling the post action, but dashboardmodel does not return
the text I entered in the textbox in the model.
Please help..
No comments:
Post a Comment