在一个colution文件中,我有几个项目.UI(ASP.Net mvc)项目,我的休息服务项目,DTO项目,业务逻辑项目和数据访问。现在我的服务项目的控制器需要与我的UI(ASP.Net MVC)项目的控制器交谈,并获取在表单中输入的数据并将其发送到数据库。我完全不确定我应该在UI项目的控制器类中提出的逻辑。 UI项目sepratley也有实体类。需要帮助!!
This is the POST method in my services controller
// POST api/Maintenance
[HttpPost]
public IHttpActionResult Post([FromBody]Maintenance maintenance)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
maintenanceLogic.Insert(maintenance);
return CreatedAtRoute("DefaultApi", new { id = maintenance.WorkID }, maintenance);
}
这是将访问上述方法uri的方法。此方法位于我的UI项目的控制器类中。我提出了一个逻辑。但我认为它不正确。
[HttpPost, Route("/maintenance/CreateMaintenanceOrder")]
public PartialViewResult CreateMaintenanceOrder([FromBody] Maintenance Model)
{
Model.CheckItems = maintenanceViewModel.CheckItems;
Model.CrewMembers = maintenanceViewModel.CrewMembers;
Model.WorkID = ++SessionUtility.CurrentMaintenanceID;
try
{
var uri = "api/Maintenance/Post ";
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri("http://localhost:8961");
Task<String> request = httpClient.GetStringAsync(uri);
Model = JsonConvert.DeserializeObject<List<Maintenance>>(request.Result);
}
maintenanceViewModel.MaintenanceOrders.Add(Model);
}
catch (AggregateException e)
{
}
maintenanceViewModel.MaintenanceOrders.Add(Model);
return PartialView("_Search", maintenanceViewModel);
}
答案 0 :(得分:0)
您正尝试使用GetAsync调用Post方法,并且您似乎没有将Rest服务方法所需的维护对象作为输入传递。请尝试以下 -
<td class="active"><?= $record->name ?></td>