簡體   English   中英

如何使用Kendo UI從ASP.NET MVC中的ActionLink傳遞變量

[英]How to pass variables from ActionLink in ASP.NET MVC with Kendo UI

有此主視圖,可使用ActionLink調用生產視圖。

<b>Start Date</b>
@(Html.Kendo().TextBox().Name("startDate"))
<b>End Date</b>
@(Html.Kendo().TextBox().Name("endDate"))
@(Html.ActionLink("Production","Index","Production"))

單擊“鏈接”后,需要傳遞2個文本框的內容(startDate和endDate),以使它們被稱為Production的控制器使用。

public class ProductionController : Controller
   {

    readonly Data.OPMSProductionEntities _opms = new Data.OPMSProductionEntities();

    public ActionResult Index() {
           return View();
     }


    public JsonResult Get([DataSourceRequest]DataSourceRequest request)
      {

          var products = ConvertOutputOfAdminAssociateSPToAList(startDate,endDate);

          return this.Json(products.ToDataSourceResult(request));
       }

這是Kendo Grid,它在Production視圖中顯示數據

@(Html.Kendo().Grid<Production>().Name("Production").Columns(c => {
    c.Bound(p => p.Sl_No).Width(1);
    c.Bound(p => p.DateProcessed).Format("{0:MM-dd-yyyy}");
    c.Bound(p => p.Remarks);
    c.Bound(p => p.RequestedAmount).Format("{0:c}");
    })
    .DataSource(d => d
        .Ajax()
        .Read(r => r.Action("Get", "Production"))
        .PageSize(8)

為了傳遞文本框的動態值,您將需要使用javascript構造網址。

更改您的操作鏈接以為其指定ID(或手動創建)

<a id="MyLink" href="#">Production</a>

腳本

$('#MyLink').click(function(e) {
  e.preventDefault();
  var url = '@Url.Action("Index", "Production")';
  window.location.href = url + '?startDate=' + $("#startDate").val() + '&endDate=' + $("#endDate").val();
});

然后更改索引方法

public ActionResult Index(DateTime startDate, DateTime endDate)
{
  ....
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM