从JavaScript加载视图 [英] Load view from javascript
本文介绍了从JavaScript加载视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在页面上有一个按钮,当我点击按钮时想要将两个参数传递给一个动作方法:
@ Html.DropDownList(compId,新的SelectList(@ ViewBag.Comps,Id,Name), - select Comp - ,new {id =ddlComp})
@ Html.DropDownList(divId,新的SelectList(@ ViewBag.Div,Id,Name), - select Division--,new {id =ddlDiv})
< 输入 < span class =code-attribute> type = button id = btnNew value = 添加新 / >
...
< script type = text / javascript >
$( #btnNew)。click( function (){
var compid = $( #ddlComp)。 VAL();
var divid = $( #ddlDiv 跨度>)VAL();
var url = ../ Admin / NewItems跨度>;
// ?这里叫做行动方法是什么?
// 当我使用......时/ span>
$ .get(url,{compId:compid,divId:divid});
// 操作被调用但页面未加载
)}
我在剧本的剧本中打电话给什么?
行动方法......
public ActionResult NewItems( string compId, string divId)
{
// 获取一些数据... var items = db.SomeTable.Where(...);
return 查看(items.ToList());
}
行动返回新页面。
谢谢
解决方案
( # btnNew)。点击( function (){
var compid =
( #ddlComp)。val();
var divid =
( #ddlDiv)。val();
var url = ../ Admin / NewItems;
// ?这里称之为Action方法?
// 当我使用...
I have a button on a page and want to pass two parameters to an action method when I click the button:
@Html.DropDownList("compId", new SelectList(@ViewBag.Comps, "Id", "Name"), "-- select Comp --", new {id="ddlComp"}) @Html.DropDownList("divId", new SelectList(@ViewBag.Div, "Id", "Name"), "-- select Division--", new {id="ddlDiv"}) <input type="button" id="btnNew" value="Add New"/> ... <script type=text/javascript"> $("#btnNew").click(function(){ var compid = $("#ddlComp").val(); var divid = $("#ddlDiv").val(); var url = "../Admin/NewItems"; // ? What goes here to call the Action Method? // When I use... $.get(url, {compId: compid, divId: divid}); // the action is called but the page is not loaded )}
What call do I make in the script to the Action?
The Action Method...
public ActionResult NewItems(string compId, string divId) { // get some data... var items = db.SomeTable.Where(...); return View(items.ToList()); }
The Action returns a new page.
Thanks解决方案("#btnNew").click(function(){ var compid =
("#ddlComp").val(); var divid =
("#ddlDiv").val(); var url = "../Admin/NewItems"; // ? What goes here to call the Action Method? // When I use...
这篇关于从JavaScript加载视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文