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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -