or
Hi There,
I have a complex model in view. But, i sended simple example for subject.
Main View Model :
public class ErpProductModel
{
public string Title { get; set; }
public string Code { get; set; }
public string ShortCode { get; set; }
public int MinStock { get; set; }
public int ShelfLife { get; set; }
public int CategoryId { get; set; }
public int TaxCategoryId { get; set; }
public decimal AmountInProduct { get; set; }
public int MeasureWeightId { get; set; }
public int CountryId { get; set; }
public int StatusId { get; set; }
public List<ErpProductPackageTypeModel>? PackageTypes { get; set; } = [];
}
PackageTypes Model :
public record ErpProductPackageTypeModel
{
public int? ProductId { get; set; }
public string Barcode { get; set; }
public int Quantity { get; set; }
public string? PackageType { get; set; }
public int PackageTypeId { get; set; }
public List<SelectListItem> AvailablePackageTypes { get; set; } = [];
}
View Source :
<script type="text/x-kendo-tmpl" id="packageTypeTemplate">
<div class="card widget widget-info">
<div class="card-body">
<div class="widget-info-container">
<div class="widget-info-image" style="background: url('@Url.Content("/Assets/Images/barcode_mock.png")')"></div>
<h5 class="widget-info-title">#=Barcode#</h5>
<p class="widget-info-text">#=PackageType# / #=Quantity# PCS</p>
</div>
</div>
</div>
</script>
@(Html.Kendo().ListView<ErpProductPackageTypeModel>()
.Name("package-types")
.BindTo((IEnumerable<ErpProductPackageTypeModel>)Model.PackageTypes)
.TagName("div")
.Bordered(false)
.Layout("grid")
.Grid(p=> p.Cols(4).Gutter(20))
.ClientTemplateId("packageTypeTemplate")
.HtmlAttributes(new { @class= "rubi-listview package-types" })
.DataSource(dataSource =>
dataSource.Ajax()
.Batch(true)
.ServerOperation(false))
)
Controller Post Method :
[HttpPost]
public virtual async Task<IActionResult> EditAsync(ErpProductModel model)
{
var erpProduct = await _erpProductService.GetErpProductAsync(model.Id);
if (erpProduct == null)
return RedirectToAction("List");
erpProduct = model.ToEntity(erpProduct);
await _erpProductService.UpdateErpProductAsync(erpProduct);
return RedirectToAction("Edit", new { id = erpProduct.Id });
}
hi
i need to pass parameter or model for ListView (not Model Page) to partialView Page in listView with use ClientTemplateId
my code is:
<script type="text/x-kendo-tmpl" id="template">
@Html.Partial("_myPartialView",new MSG_UserMessagesList_Ex_For_Model { Name = #: FileName # });
</script>
@(Html.Kendo().ListView<MSG_UserMessagesList_Ex_For_Model>()
.Name("listView")
.TagName("div")
.HtmlAttributes(new { style = "height:100%; width: 100%;" })
.ClientTemplateId("template")
.DataSource(dataSource => dataSource
.Ajax()
.Read(r => r.Url(@Url.Page("MsgList", "MSG_UserMessagesList_Ex")).Data("forgeryToken"))
)
)
Hey,
Let's say that I have a ListView with comments:
@(Html.Kendo().ListView<Adelante_ERP_GSBK.Models.ProjectComment>()
.Name("listView")
.TagName("div")
.ClientTemplateId("template")
.HtmlAttributes(new {style = "border: none;"})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetComments", "ProjectComment", new {projectId = Model.Id}))
))
Template
<script type="text/x-kendo-tmpl" id="template">
<div class="post">
<div class="user-block" style="margin-bottom: 0;">
<span class="username" style="display: inline; margin-left: 10px;">
#:User.Name#
</span>
<span class="description" style="display: inline; margin-left: 5px">
#:kendo.toString(CommentDate, "d")#
</span>
<a onclick="showInPopup('@Url.Action("AddOrEdit", "ProjectComment", null, Context.Request.Scheme)/#:Id#', 'Edit')" style="cursor: pointer;" title="Dodaj">
<i class="fa-solid fa-pen-to-square"></i>
</a>
<a onclick="showInPopup('@Url.Action("Delete", "ProjectComment", null, Context.Request.Scheme)/#:Id#', 'Delete?')" style="cursor: pointer;" title="Usuń">
<i class="fa-solid fa-xmark"></i>
</a>
</div>
<div style="margin-left: 10px;">
#:CommentContent#
</div>
</div>
</script>
Everything works fine, but I don't want that all users always see edit/delete buttons.
Edit button should be visible only for author and administrator, delete only for administrator.
Does anyone have an idea how can I do this?