비주얼 스튜디오 익스프레스 2012을 사용하여이 MVC4 웹 응용 프로그램 및 SQL 2008 R2는 ... MVC4 : w 저장 프로 시저/여러 매개 변수
나는 하나 개의 매개 변수를 받아 저장 프로 시저를하는 데 사용 때, 그리고 내 MVC 모델 저장 프로 시저가 포함되어 있으므로 성공적으로Controller
에서 호출하고
Json
결과를 얻으실 수 있습니다.
이제 두 개의 매개 변수를 허용하도록 저장 프로 시저를 업데이트했습니다. 내 MVC 모델을 새로 고쳤지만 두 개의 매개 변수를 전달할 때 내 컨트롤러에서 저장 프로 시저를 올바르게 호출 할 수 없습니다.
PROCEDURE [dbo].[GetDependencyNodes]
@CISearchString nvarchar(100)
올드 컨트롤러 :
namespace CMDB.Controllers
{
public class GoJSDiagramNodesAndLinksController : Controller
{
private CMDBEntities db = new CMDBEntities();
public ActionResult GetDependencyNodes(string CISearchString)
{
return Json(db.GetDependencyNodes(CISearchString).ToList(), JsonRequestBehavior.AllowGet);
}
}
}
여기 내 새 저장 프로 시저 및 컨트롤러 여기
내 오래된 저장 프로 시저와 하나 개의 매개 변수를 사용하여 컨트롤러 (이 작품)입니다 두 가지 매개 변수를 수락합니다 :
PROCEDURE [dbo].[GetDependencyNodes]
@CISearchString nvarchar(100),
@ExcludeString nvarchar(100)
새로운 컨트롤러 :
이'INT'가 '에 대한 정의가 포함되어 있지 않습니다 : 비주얼 스튜디오 익스프레스 2012 년
namespace CMDB.Controllers
{
public class GoJSDiagramNodesAndLinksController : Controller
{
private CMDBEntities db = new CMDBEntities();
public ActionResult GetDependencyNodes(string CISearchString, string ExcludeString)
{
return Json(db.GetDependencyNodes(CISearchString, ExcludeString).ToList(), JsonRequestBehavior.AllowGet);
}
}
}
, 나는 진술 내 "반환 JSON"줄에 오류가 ToList '및'Int '형식의 첫 번째 인수를 수락하는'ToList '확장 메서드가 없습니다.
이return Json(db.GetDependencyNodes(CISearchString, ExcludeString).ToString().ToList(), JsonRequestBehavior.AllowGet);
오류가 도망 간다하지만 컨트롤러가 -1을 반환하는 대신 올바른 JSON 결과의 :
return Json(db.GetDependencyNodes(CISearchString, ExcludeString).ToList(), JsonRequestBehavior.AllowGet);
에 : 나는에서 라인을 변경하는 경우
. 필자는 SQL 관리자에서 저장 프로 시저를 테스트했으며 예상 된 결과를 볼 수 있습니다.
/// <summary>
/// No Metadata Documentation available.
/// </summary>
/// <param name="cISearchString">No Metadata Documentation available.</param>
/// <param name="excludeString">No Metadata Documentation available.</param>
public int GetDependencyNodes(global::System.String cISearchString, global::System.String excludeString)
{
ObjectParameter cISearchStringParameter;
if (cISearchString != null)
{
cISearchStringParameter = new ObjectParameter("CISearchString", cISearchString);
}
else
{
cISearchStringParameter = new ObjectParameter("CISearchString", typeof(global::System.String));
}
ObjectParameter excludeStringParameter;
if (excludeString != null)
{
excludeStringParameter = new ObjectParameter("ExcludeString", excludeString);
}
else
{
excludeStringParameter = new ObjectParameter("ExcludeString", typeof(global::System.String));
}
return base.ExecuteFunction("GetDependencyNodes", cISearchStringParameter, excludeStringParameter);
}
어떤 아이디어 : 여기
은 GetDependencyNodes 내 파일 CMDBModels.Desginer.cs에서 일부 코드를 무엇입니까?
감사합니다.
컴파일러는 거짓말을하지 않습니다. GetDependencyLinks가 문제의 근원이라고 가정하는 정수를 반환합니다. –
두 개의 매개 변수를 전달할 때 "GetDependencyLinks"저장 프로 시저를 호출하는 구문이 올바른 것으로 보입니까? 하나에서 두 개의 매개 변수로 변경하면 ToList()가이 오류를 발생시키는 이유는 확실하지 않습니다. – user2166281
실제로 매개 변수를 저장 프로 시저에 전달하는 방법을 말할 수 없습니다. 실제로 GetDependencyLinks 메서드에 의해 수행되기 때문입니다. 코드를 GetDependencyLinks 메서드에 게시 할 수 있습니까? –