How to pass parameters into cshtml page

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
Dear Sir/Madam,

I have an issue regarding pass parameters into cshtml page.
I have a DataTablesModel in the configure page, this table have many columns including button Edit, when click on this button, it will call Edit function and redirect to Edit page. I want to get appropriately Id to do in Edit function, but Id value is always 0.
How can I get the Id value in Edit function? please help me

Thank & Best Regards,

#Configure.cshtml
....
<div class="panel panel-default">
  <div class="panel-body">
    @await Html.PartialAsync("Table", new DataTablesModel
       {
         Name = "grid",
         UrlRead = new DataUrl("List", "Custom",null),
         Paging = false,
        ColumnCollection = new List<ColumnProperty>
    {
      new ColumnProperty(nameof(CustomModel.Id))
      {
        Title = "ID",
        Width ="300"
      },
    
      new ColumnProperty(nameof(CustomModel.Id))
      {
        Title = T("Admin.Common.Edit").Text,
        Width = "100",
        Render = new RenderButtonEdit(new DataUrl("~/Admin/Custom/Edit/"))
      }
         }
       })
  </div>
</div>

#CustomControler
namespace Nop.Plugin.Widgets.Custom.Controllers
{
    [Area(AreaNames.Admin)]
    [AuthorizeAdmin]
    [AutoValidateAntiforgeryToken]
    public class CustomController : BasePluginController
    {
    public IActionResult Configure()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageWidgets))
                return AccessDeniedView();
      ...
    }
    [HttpPost]
    public IActionResult Configure(CustomModel model)
  {
    if (!ModelState.IsValid)
    {
      return Configure();
    }
    ...
  }
  public virtual IActionResult List(CustomSearchModel searchModel)
  {
    ...
    return json(model);
    }
  public virtual IActionResult Edit(int Id)
  {
    var model = new CustomModel();
    model.Id = Id; //Id is always 0
    return View("~/Plugins/Custom/Views/Edit.cshtml", model);
  }
  }
}
3 years ago
What if you set a breakpoint at
 public virtual IActionResult List(CustomSearchModel searchModel)
  {
    ...
    return json(model);


Do the list item objects have their Id property set?
3 years ago
New York wrote:
What if you set a breakpoint at
 public virtual IActionResult List(CustomSearchModel searchModel)
  {
    ...
    return json(model);


Do the list item objects have their Id property set?


Hi, yes, it return a list of items with properly Id, and when I move the mouse onto Edit button, I found that the status at the taskbar show like that ../Admin/Custom/Edit/Id.

However, I don't know how to get the Id in Edit function. Kindly show me what I am wrong. Thanks
2 years ago
Hi

Did you manage to get the passing of parameters done to cshtml pages?

Thanks in advance
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.