我尝试将参数接收的 int 变量与 DB 中的 int 字段进行比较。
控制器中的功能:
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult getServicoID(string serie, int numDoc)
{
try
{
var result = db.Servicos.Where(dados => dados.DadosComerciais.Serie == serie && dados.DadosComerciais.NumDoc == numDoc); // i think the problem is here - dados.DadosComerciais.NumDoc == numDoc
return Json(result, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message }, JsonRequestBehavior.AllowGet);
}
}
函数js:
function AddServContratado() {
//Buscar ServicoID da tabela servicos para guardar na ServicoContratado
$.getJSON("/Contrato/getServicoID", { serie: $("#Serie").val(), numDoc: $("#NumDoc").val() },
function (result) {
var servicoID = result.ServicosID;
alert(result.ServicosID);
});