jquery - Pass values from view to controller model on httppost from ajaxcall not working -


i have requirement insert text entered in textareafor when text changed in textbox.i used jquery change function done.i controller hit on actionmethod ajax but, text view not getting passed model. (code used: mvc4 /entity dbfirst/ razor) here detailed code.

controller:

public actionresult index() {                 return view(); } public actionresult dailynotes() {                 return view(); }  //i’m getting code hit ajaxcall, dashboard model null???????? tbldailynotes note = new tbldailynotes(); [httppost] public actionresult dailynotes(dashboardviewmodel model) {     int noteid = 0;     model.dailynotes = note.note;     _scheduler.insertdailynote(note);//this sp insert 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 ajax calling post action, dashboardmodel not return text entered in textbox in model.

please help..

edit 1: /not working

 $("#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");           });     }); 

if want pass model on view controller using ajax call can use

data: $('form').serialize() 

if want pass text 1 parameter type string needed passed , not whole model.

for second option can use

var dailynotes=$('#dailynotes').val(); 

and in ajax call

data:{dailynotes:dailynotes}; 

and controller action accept argument of type string dailynotes


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -