简体   繁体   中英

How to sent parameter token from kendo grid, in url.action .NET MVC

I want to sent parameter to view via @Url.Action

I've tried something like that, I don't want to sent a default parameter. I want to sent the value of id column of grid selected row.

<input type="button" value="Sınıf Listeleri Raporu" onclick="window.location.href='@(Url.Action("SinifListeleri", "Tanim", new { BasvuruId= "value"}).ToString())   ';" />

So how can I set the value as value of id column of grid selected row. If I could call a javascript function as return value, it will be useful for me.

And also I can use anything except ajax because ajax conflicted with other functions of my project.

---- Second Explanation--- Sory for my English

I have a grid. It has id column. I select a row, then press details button. A window opens. There is a download link there. This link call Download function from BasvuruController. This function need an Id parameter. I can't find how to sent this selected row Id to this function.

----Kendo Grid Code ----

@(Html.Kendo().Grid(Model)
.Name("basvurular")
.Columns(columns =>
{
    columns.Command(command => command.Custom("ViewDetails")
.Text("Göster").HtmlAttributes(new { @onClick="ff()" })
).Width(80);
    columns.Bound(p => p.KisiAdSoyad).Width(150).Filterable(f => f.Extra(false)).HtmlAttributes(new { styles = "min-length:150px" });
    columns.Bound(p => p.DonemKursVeDonemSinifi).Width(200).Title("Kurs ve Şubesi").Filterable(f => f.Extra(false)).HtmlAttributes(new { styles = "min-length:200px" });
    columns.Bound(p => p.BasvuruZamani).Width(150).Format("{0:yyyy/MM/dd HH:mm:ss }").HtmlAttributes(new { styles = "min-length:150px" });
    columns.Bound(p => p.ToplamUcret).Width(80).Format("{0:c2}").Title("Ücret").Filterable(false).HtmlAttributes(new { styles = "min-length:80px" });
    columns.Bound(p => p.DonemTanim).Width(160).Filterable(filterable => filterable.UI("DonemFilter").Extra(false)).Title("Dönem").HtmlAttributes(new { styles = "min-length:160px" });
    columns.Bound(p => p.DurumKoduTanim).Width(130).Filterable(filterable => filterable.UI("DurumFilter").Extra(false)).Title("Durum").HtmlAttributes(new { styles = "min-length:130px" });
    columns.Bound(p => p.Id).Visible(false);
    columns.Command(command => { command.Edit().Text("Güncelle"); command.Custom("Onay").Text("Onayla/Reddet").Click("OnayEkrani"); }).Width(250).HtmlAttributes(new { styles="min-length:250px"});
})
    .Events(e => e.Edit("clickUpdate").DataBound("donemFilterControl"))
    .Editable(editable => editable.Mode(GridEditMode.PopUp)
                                .Window(conf => conf.Title("Yeni Başvuru"))
                                .TemplateName("BasvuruTemplate")
                                .DisplayDeleteConfirmation("Seçili kaydı silmek istediğinizden emin misiniz?")
             )
.Pageable()
.Sortable()
.Scrollable()
.Selectable()
    .Events(e => e.FilterMenuInit("al"))
.HtmlAttributes(new { style = "height:350px; width:auto" })
.DataSource(dataSource => dataSource
    .Ajax()
    .Read(read=>read.Action("BasvuruGridRead","Tanim"))
    .Sort(sort => sort.Add("KisiAdSoyad").Ascending())
    .PageSize(7)
    .Filter(f => f.Add(x => x.DonemTanim).IsEqualTo(@OnlineKursKayit.Helpers.Helper.Islemci.GuncelDonemAra().GetDescription()))
    .Model(model => model.Id(p => p.Id))
    .Update(update => update.Action("BasvuruyuGuncelle", "Tanim"))
)

)

------ JavaScript Function which returns Id of selected index of grid----

function basvuruId(){
    var grid = $("#basvurular").data("kendoGrid");
    var rows = grid.select();
    var BasvuruId=grid.dataItem(rows).Id;
    return BasvuruId;
}

when you click on detail button you need to pass id (row values) to that request and you get that value in your action , and inside your action use viewbag to save and to pass that value to your other view. and now you have row id and use it where ever you want to use it.

function basvuruId(){
    var grid = $("#basvurular").data("kendoGrid");
    var rows = grid.select();
    var BasvuruId=grid.dataItem(rows).Id;
    window.location.href = '@(Url.Action("Download", "Basvuru").ToString())?BavuruID=' + BasvuruId;
    return false;

I found finally. Done with httpGet from javaScript function.

You are probably calling Url.Action in a View so you should have a Model where you stored the Id you need. Since you are not providing any code I'm just guessing that what you need to do is:

@Url.Action("Download", "Basvuru",new { basvuruId = Model.YourId })

If you are iterating some sort of list with a foreach you will end up with something like:

foreach(var item in Model) {
  // some code

  // please be aware that calling Url.Action like this makes little sense,
  // but since you didn't tell us what you are doing it's hard to guess.
  // be also aware of the fact that Html.Action != Url.Action
  @Url.Action("Download", "Basvuru",new { basvuruId = item.YourId })

  //some other code
}

I'm not quite sure where you are using Url.Action but it's very unlikely you need a call to .toString()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM