1
這是我的MVC控制器代碼。想要將對象從MVC控制器傳遞到Web API控制器
[HttpPost]
public async Task<IActionResult> InsertNewStudentAsync(ViewModel.StudentPersonalDetailsViewModel ob)
{
StudentModel obj = ViewModel.StudentPersonalDetailsViewModel.Translate(ob);
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:52494/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var bodyData = ViewModel.StudentPersonalDetailsViewModel.Translate(ob);
//HttpContent ob = new HttpContent();
var response = await client.PostAsync("api/Student/InsertStudent",obj);
}
return View();
}
在線路var response = await client.PostAsync("api/Student/InsertStudent",obj);
它表示我示出在物鏡的錯誤
錯誤CS1503參數2:不能從 'SMS.Domain.Models.StudentModel' 轉換爲' System.Net.Http.HttpContent'
如何將該對象傳遞給我的API控制器。