本文介绍了如何在视图中调用控制器动作方法,返回一个int值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我从数据库中收集一个值。我希望将该值发送给view.and他们想检查该值。 我尝试过: 控制器中的操作方法 公共ActionResult BookSet(长?ClassId) { 列表< bkselect> Bk =新列表< bkselect>(); Bk =(来自db.Student_Book_Allow_Quantity中的a 其中a.Class_Id == ClassId 选择新的BKselect() { Class_Id = a.Class_Id, Student_Book_Allow_Quantity_Id = a.Student_Book_Allow_Quantity_Id })。OrderBy(a => a.Class_Id).ToList(); ViewBag.BKselect = Bk.ToList(); 返回PartialView(); } 视图部分 $(#FieldListTable)。append(' < input class =addNewButtonstyle =float:left; margin-left:0px;type =buttonvalue =Addid =btnAdd/>< input class =addNewButtonstyle =float:left; margin-left:0px;type =buttonid =btnRemovevalue =Remove/> BOOkS LISt @ Html.ListBox(LstSignInAuthority,Enumerable.Empty< SelectListItem>(),new {@id =LstSignInAuthority,style =width:200px; height: 130px;}) '); 功能部分 功能Addbook(){ var bkLst = $(#LstSignInAuthority); if(bkLst!==){ $(document).ready(function () var newValue = $('input [name = Book_Name]')。val(); var TotalItems = document.getElementById(LstSignInAuthor ity)。options.length; if(TotalItems< 5){ $('#LstSignInAuthority')。append('< option value ='+ newValue +'>'+ newValue +'< / option>'); $(#Book_Name)。val(); $(#Title)。val(); $(#Book_Category_Name)。val(); } }) ; } } I collecting a value from database. and i want to send that value to view.and their i want to check that value.What I have tried:In Action method in controllerpublic ActionResult BookSet(long? ClassId) { List<bkselect> Bk = new List<bkselect>(); Bk= (from a in db.Student_Book_Allow_Quantity where a.Class_Id==ClassId select new BKselect() { Class_Id=a.Class_Id, Student_Book_Allow_Quantity_Id=a.Student_Book_Allow_Quantity_Id }).OrderBy(a => a.Class_Id).ToList(); ViewBag.BKselect = Bk.ToList(); return PartialView(); }in view part $("#FieldListTable").append('<input class="addNewButton" style="float: left; margin-left: 0px;" type="button" value="Add" id="btnAdd" /><input class="addNewButton" style="float: left; margin-left: 0px;" type="button" id="btnRemove" value="Remove" />BOOkS LISt@Html.ListBox("LstSignInAuthority", Enumerable.Empty<SelectListItem>(), new { @id = "LstSignInAuthority", style = "width:200px;height:130px;" })');fuction part function Addbook() { var bkLst = $("#LstSignInAuthority"); if (bkLst !== "") { $(document).ready(function () { var newValue = $('input[name=Book_Name]').val(); var TotalItems = document.getElementById("LstSignInAuthority").options.length; if (TotalItems < 5) { $('#LstSignInAuthority').append('<option value="' + newValue + '">' + newValue + '</option>'); $("#Book_Name").val(""); $("#Title").val(""); $("#Book_Category_Name").val(""); } }); } }推荐答案 (#FieldListTable)。append(' < input class =addNewButtonstyle = float:left; margin-left:0px;type =buttonvalue =Addid =btnAdd/>< input class =addNewButtonstyle =float:left; margin-left:0px ;type =buttonid =btnRemovevalue =Remove/> BOOkS LISt @ Html.ListBox(LstSignInAuthority,Enumerable.Empty< SelectListIt em>(),new {@id =LstSignInAuthority,style =width:200px; height:130px;}) '); 功能部分 功能Addbook(){ var bkLst = ("#FieldListTable").append('<input class="addNewButton" style="float: left; margin-left: 0px;" type="button" value="Add" id="btnAdd" /><input class="addNewButton" style="float: left; margin-left: 0px;" type="button" id="btnRemove" value="Remove" />BOOkS LISt@Html.ListBox("LstSignInAuthority", Enumerable.Empty<SelectListItem>(), new { @id = "LstSignInAuthority", style = "width:200px;height:130px;" })');fuction part function Addbook() { var bkLst = (#LstSignInAuthority); if(bkLst!==){ ("#LstSignInAuthority"); if (bkLst !== "") { (document).ready(function(){ var newValue = (document).ready(function () { var newValue = 这篇关于如何在视图中调用控制器动作方法,返回一个int值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-03 08:29