asp.net mvc - Redirecting from ane action to another controller action in mvc -


this code want post data(date of calendar here) "index" action of "home" controller , want save data in database , @ same time want redirect action of controller i.e "index" action of "home" controller

here jquery code below,

  function getdate() {              $('.cal_daybox').on('click', function () {             var timestamp = parseint($(this).attr('id'));                  var day = new date(timestamp);                  alert("you clicked " + day.todatestring());                  var url = '@url.content("~/home/index")';                 var date = day.todatestring();                 $.ajax({                     type: "post",                     url: url,                     data: { date: day.todatestring() },                     datatype:"json"                 });                                return false;             });   

eventscontroller.cs

  public actionresult index()     {         return view(db.events.tolist());     } 

homecontroller.cs

[httppost]     public actionresult index(datetime date)     {              date dt = new date();             dt.startdate = date;             db.dates.add(dt);                db.savechanges();             return redirecttoaction("index", "events", new { id = dt.dateid });     } 

your index action of events controller not have parameter recieve dateid value.it unable find action recieve dateid val.

you need either modify existing action or add action overload this

public actionresult index(datetime dateid) {     //do val }  public actionresult index() {     return view(db.events.tolist()); } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -