I am at learning phase of web API and I want to POST data into database from the view by using WebAPI. How to hit the WebAPI from MVC.
Here is Controller
[HttpPost]
public ActionResult PatientMedicines(DomainModels.Orders.Medicines medicine, string key, string username, string FullName, string Phone, string CNIC, string address, string Email, DateTime dateofbirth, string Gender, string PaymentMethod, string PostedPrescription)
{
SessionUser user = Session["User"] as SessionUser;
medicine.add_with_api( key,user.Username, FullName, Phone, CNIC, address, Email, dateofbirth, Gender, PaymentMethod, PostedPrescription);//
return View(new ViewModels.Orders.Medicines(user.Username));
}
Now Here is the Model
string baseUrl = ServerConfig.server_path + "/api/Payment/AddMedicineOrder";
Dictionary<string,string> parameters = new Dictionary<string,string>();
parameters.Add("username",username);
parameters.Add("FullName", FullName);
parameters.Add("Phone",Phone);
parameters.Add("CNIC",CNIC);
parameters.Add("address",address);
parameters.Add("Email",Email);
parameters.Add("dateofbirth",dateofbirth.ToShortDateString());
parameters.Add("Gender",Gender);
parameters.Add("PaymentMethod",PaymentMethod);
parameters.Add("image","null");
var response =Common.ReadFromAPI<API(baseUrl,"Post",parameters);
return true;
How to hit this from by using POST method to insert data through api?