I'm currently using Kendo Grid for ASP.Net Core MVC.
So, I created a column with a group of options.
columns.Template("<div class='btn-group'></div>")
.Title("").Width(100);
Then with jquery:
$(this).find(".btn-group").append("<button type='button' class='btn btn-light btn-sm dropdown-toggle' data-bs-toggle='dropdown' aria-expanded='false'>Actions<i class='mdi mdi-chevron-down'></i>.
</button>
<ul class='dropdown-menu dropdown-menu-end'>
<li>
<a href='advertisers/edit/@Html.Raw(Model.Select(x => x.AdvertiserId));'>
<button class='dropdown-item' type='button'>Edit</button></a>
</li>
<li>
<button class='dropdown-item text-danger' type='button'>Mark Inactive</button>
</li>
</ul>");
As you can see I have a button Edit pass the Model.Id from the referenced model, I tried:
@Html.Raw(Model.Select(x => x.AdvertiserId))
Or
@Model.Select(x => x.AdvertiserId)
When I try this the URL shows as:
edit/System.Linq.Enumerable SelectListIterator`2[Lib.Models.Advertiser,System.Int32];
But none of them works; how can I get this done? Regards
UPDATE:
I added the Id as a hidden column:
columns.Bound(x => x.AdvertiserId)
.Hidden();
So I can access all of them with jQuery as: dataItem.AdvertiserId
How can I add it on each row <a href='advertisers/edit/'>
?
CodePudding user response:
If you want to pass an array into query,try to use:
<a href='advertisers/edit@(Html.Raw("?AdvertiserId=" String.Join("&AdvertiserId=", Model.Select(x => x.AdvertiserId).ToArray())))'>
<button class='dropdown-item' type='button'>Edit</button></a>
And use action like this:
public IActionResult edit(int[] AdvertiserId){
...
}
CodePudding user response:
I fix this by adding the Url as a constant like:
const advertiserEditUrl = 'advertisers/edit?advertiserId=' dataItem.AdvertiserId;
Then in href
<a href='" advertiserEditUrl "'></a>