0

I have an asp.net core MVC project I am creating custom scaffolding template files

I am following this answer to add custom scaffolding template pages

on Details page I want o add link to Listing, Edit and Delete page as below

@using System.Linq
@@model @Model.ViewDataTypeName

@:    <div class="card-body py-2">
@:        <a asp-action="Delete" asp-route-id="@@Model.pkName" class="float-right btn-floating btn-sm btn-danger m-0" title="Delete @Model.ViewDataTypeShortName Record"><i class="fa fa-trash"></i></a>    
@:        <a asp-action="Edit" asp-route-id="@@Model.pkName" class="float-right btn-floating btn-sm btn-warning m-0 mr-2" title="Edit @Model.ViewDataTypeShortName Record"><i class="fa fa-edit"></i></a>   
@:        <a asp-action="Index" class="float-right btn-floating btn-sm btn-info m-0 mr-2" title="Back to @Model.ViewDataTypeShortName listing page"><i class="fa fa-arrow-left"></i></a>    
@:        <h4 class="mb-2 mb-sm-0 pt-1">@Model.ViewDataTypeShortName Details</h4>
@:    </div>

Notice asp-route-id="@@Model.pkName" in above example, Actualloy here I need to put primaryKey field name dynamically, @@Model.pkName is not a valid property but I just wanted to show something here.

alamnaryab
  • 1,480
  • 3
  • 19
  • 31
  • Hi @alamnaryab, so how do you design your model and what is your DbContext like? – Rena Jun 14 '22 at 02:24
  • I am using codefirst approach with `ApplicationDbContext`, some models primary keys are named `ID`, `recId`, `id` etc – alamnaryab Jun 14 '22 at 08:42
  • Hi @alamnaryab, It is better for you to show us what do you change for the custom scaffolding template and your model design. By default scaffolding, it will display the primary key on `asp-route-id`. – Rena Jun 15 '22 at 06:19
  • Dear @Rena default scaffolding was having only `

    @Model.ViewName

    ` while I replaced with content displayed in `div.card-body`, in above code `@@model.pkName` is throwing error, I want it to display `model.id`,`model.recID`,`model.whatever_is_primarykey_field_name`
    – alamnaryab Jun 16 '22 at 07:14

0 Answers0