前端,将传值的数据封装在了renew中
data(){
return {
url: process.env.VUE_APP_BASE_API,
renew: {
organizationName: '',
groupName: '',
substationName: '',
lineName: ''
},
}
methods:{
submitForm(){
request({
url: self.url + '/api/Organization/RenewLine',
method: 'post',
headers: {
'Authorization': 'Bearer ' + getToken(),
'Content-Type': 'application/json'
},
contentType: 'application/json',
data: JSON.stringify(self.renew)
})
}
}
后端Crotoller接收
[Authorize]
[HttpPost]
[Route("RenewLine")]
public ActionResult RenewLine([FromBody] object data)
{
JObject form = (JObject)JsonConvert.DeserializeObject(data.ToString());
bool result = _organizationService.RenewLine(form);
JsonResult jr = new JsonResult(result);
return jr;
}
OrganizaService
public interface IOrganizationService
{
bool RenewLine(JObject form);
}
Service解析JSON类型,将格式转出来
public bool RenewLine(JObject form)
{
string organizationName = form["groupName"].ToString();
string groupName = form["groupName"].ToString();
string substationName = form["substationName"].ToString();
string lineName = form["lineName"].ToString();
bool result = _organizationRepository.RenewLineInfo(organizationName, groupName, substationName, lineName);
return result;
}
OrganizationRepository
public interface IOrganizationRepository
{
List<OrganizationInfo> QueryOrganizationInfo(string organizationName, string groupName, string substationName, string lineName, string perorganization);
bool RenewLineInfo(string organizationName, string groupName, string substationName, string lineName);
}