要求是這樣子的,在一個(gè)列表頁(yè)中,用戶(hù)點(diǎn)擊詳細(xì)銨鈕,帶記錄的主鍵值至另一頁(yè)。
在另一外頁(yè)中,獲取記錄數(shù)據(jù),然后顯示此記錄數(shù)據(jù)在網(wǎng)頁(yè)上。
先用動(dòng)圖演示:
昨天有分享為ng-click傳遞參數(shù) 《angularjs為ng-click事件傳遞參數(shù)》http://www.cnblogs.com/insus/p/7017737.html
上面僅僅是在ng-click傳入一個(gè)值,但是在ASP.NET MVC中,還需要把這個(gè)值傳至另外一個(gè)視圖中《ASP.NET MVC傳遞參數(shù)(model)》http://www.cnblogs.com/insus/p/6148167.html
$scope.Detail = function (code) { var objects = {}; objects.Key = code; objects.Value = ""; objects.Controller = "Code"; objects.Action = "ClauseDetail"; $http({ method: 'POST', url: '/Pass/Redirect', dataType: 'json', headers: { 'Content-Type': 'application/json; charset=utf-8' }, data: JSON.stringify(objects), }).then( function success(response) { if (response.data.Success) { window.location.href = response.data.RedirectUrl; } else { alert(response.data.ExceptionMessage); } }, function error(error) { alert(response.error.data); }); };
在ASP.NET MVC的控制器的Action接收參數(shù),獲取數(shù)據(jù)庫(kù)的數(shù)據(jù):
public ActionResult ClauseDetail() { if (TempData["Pass"] == null) return RedirectToAction("Clause", "Code"); var pass = TempData["Pass"] as Pass; TempData["Pass"] = pass; Clause c = new Models.Clause(); c.Code = pass.Key.ToString(); ClauseEntity ce = new ClauseEntity(); var model = ce.ClauseByKey(c).FirstOrDefault(); return View(model); }
上面從數(shù)據(jù)庫(kù)獲取數(shù)據(jù)后,給視圖一個(gè)model。下面是本篇所說(shuō)的重點(diǎn),怎樣把ASP.NET MVC的model傳給angularjs ng-model:
以上所述是小編給大家介紹的ASP.NET MVC中jQuery與angularjs混合應(yīng)用傳參并綁定數(shù)據(jù),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com