0

i'm having a little problem here,

I have a table based calendar view that has, on each day, an ajax link that renders some day-specific form to the user to set for the selected day.

Then I want to select the day-specific data on the partial view that opened and save them also using ajax, but I also need to pass some info that is contained in the page model, like the selected day and month, year, etc.

The partial view that is loaded when I click on the day, is going to be the place where the user will chose some hospital duty info, like the duty start-time, the end time, the doctor that is going to be in charge of the duty, and on the page Model, there is the hospital ID, the day month and year of the Duty.

So how can I send the form data plus the page model to a controller that is going to save the data on the database?

Thanks.

Diego Barreto
  • 195
  • 3
  • 13
  • You need to show some code so we can see what your currently doing, but one option would be to use `FormData` ([refer this answer](http://stackoverflow.com/questions/29293637/how-to-append-whole-set-of-model-to-formdata-and-obtain-it-in-mvc/29293681#29293681)) where you serialize the form, and then append additional data - e.g. `formData.append('someData' @Model.someValue);` –  Jul 31 '15 at 01:17

2 Answers2

0

So how can I send the form data plus the page model to a controller that is going to save the data on the database?

Instead of doing a form post, you could do a ajax post

$.ajax({
    url: 'Controller/Action',
    type: 'POST',
    data: JSON.stringify({
        'postData': postData
    }),
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: SuccessHandler,
    error: ErrorHandler,
});
Pang
  • 9,564
  • 146
  • 81
  • 122
muddassir
  • 815
  • 9
  • 16
0

i think there are at least 2 ways to do this.

first is on server side.
when you click the main page link,pass the main page model data which the child page need.url like controller/action?a=1&b=2... 1 and 2 are you main page model data.you can get these data in child action by add action method param.then you can pass them to child view use model,viewdata,viewbag

second is on client side.
you can put you main page model data to a js var(or think simply,a hidden input),and then you click the link and show you child page,the child page is part of the main page,so you can read the js var in child page.then you can do some js programe to show the js data in page

so,pass the data from main page to child action,or child page get main page data by js

chenZ
  • 920
  • 4
  • 16