내 MVC 컨트롤러의 동작이 내 jQuery 코드에서 두 번 호출되고 있습니다. 몇 가지 조사를 한 후 jQuery와 MVC 뷰에서 링크가 트리거되고 있음을 발견했습니다. 링크가컨트롤러에서 동작 메서드가 두 번 호출됩니다.
<li>
<a href="#"><i class="fa fa-circle-o"></i> Deployment Environment</a>
<ul class="treeview-menu">
@foreach (var item in ViewBag.Environments)
{
<li>
<a href="@Url.Action(@item.Name,"Configuration")" id="@item.GenericMasterId" name="environments">
<i class="fa fa-circle-o"></i>
@item.Name
</a>
</li>
}
</ul>
</li>
내가 직면하고 문제를 채워되고있다
$('.treeview-menu li a[name="environments"]').on("click", function() {
debugger;
var genericId = $(this).attr('id');
if (genericId != undefined) {
$.ajax({
type: "GET",
url: "/Configuration/Development",
data: { 'genericId': genericId } ,
datatype: "application/json",
success: function (data) { }
})
}
else {
return;
}
});
[HttpGet]
public ActionResult Development(DashBoardViewModel model, string genericId)
{
ViewBag.EnvironmentType = "Development";
DeploymentConfiguration_DAL _deploymentDal = new DeploymentConfiguration_DAL();
model.Configuration = _deploymentDal.FetchDeploymentConfigurationByEnvironmentID(Convert.ToInt32(Convert.ToInt32(genericId)));
if (model.Configuration != null)
{
return View("Index", model);
}
return View("Index");
}
보기는 응용 프로그램이 실행될 때 동적으로 생성되고있는 링크 중 하나를 클릭 한 후. 조치 메소드가 처음으로 실행되고 내 모델을 채 웁니다. 그러나 내보기에 표시하는 대신 조치 메소드가 다시 히트되고 null
을 채우고 텍스트 상자가 db 값에서 바인드되지 않기 때문에 모델에 채워집니다.
해결 방법을 알려주세요. jQuery를 사용하지 않고 내 조치 결과에서 값에 href
값을 액세스 할 수있는 방법이 있습니까? (item.Name @, "구성") = "#"HREF에 대한을 Url.Action @을 대체 할
'에 대해'html'을 표시 할 수 있습니까?treeview-menu li a [name = "환경"]'요소? –
두 개의'[name = "environments"]'요소가있는 것 같습니다. 그들이 중첩되어 있습니까? –
님이 내가 사용중인보기를 추가했습니다. –