nopSolutions/nopCommerce · error · ArgumentException

No template found with the specified id

Error message

No template found with the specified id

What it means

Thrown by TemplateController.CategoryTemplateUpdate when ICategoryTemplateService.GetCategoryTemplateByIdAsync(model.Id) returns null. This is the update endpoint for category display templates (behind MANAGE_MAINTENANCE permission); the id comes from the posted CategoryTemplateModel. ModelState is validated first, then the template is looked up; a null result throws ArgumentException.

Source

Thrown at src/Presentation/Nop.Web/Areas/Admin/Controllers/TemplateController.cs:84

    [CheckPermission(StandardPermission.System.MANAGE_MAINTENANCE)]
    public virtual async Task<IActionResult> CategoryTemplates(CategoryTemplateSearchModel searchModel)
    {
        //prepare model
        var model = await _templateModelFactory.PrepareCategoryTemplateListModelAsync(searchModel);

        return Json(model);
    }

    [HttpPost]
    [CheckPermission(StandardPermission.System.MANAGE_MAINTENANCE)]
    public virtual async Task<IActionResult> CategoryTemplateUpdate(CategoryTemplateModel model)
    {
        if (!ModelState.IsValid)
            return ErrorJson(ModelState.SerializeErrors());

        //try to get a category template with the specified id
        var template = await _categoryTemplateService.GetCategoryTemplateByIdAsync(model.Id)
            ?? throw new ArgumentException("No template found with the specified id");

        template = model.ToEntity(template);
        await _categoryTemplateService.UpdateCategoryTemplateAsync(template);

        return new NullJsonResult();
    }

    [HttpPost]
    [CheckPermission(StandardPermission.System.MANAGE_MAINTENANCE)]
    public virtual async Task<IActionResult> CategoryTemplateAdd(CategoryTemplateModel model)
    {
        if (!ModelState.IsValid)
            return ErrorJson(ModelState.SerializeErrors());

        var template = new CategoryTemplate();
        template = model.ToEntity(template);
        await _categoryTemplateService.InsertCategoryTemplateAsync(template);

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Return to the category templates list; if the template is gone, it was deleted externally and the edit is no longer valid.
  2. Recreate the template if it was removed in error, then edit it again.
  3. For programmatic updates, confirm the template exists before posting the update model.
  4. Catch ArgumentException and return a localized ErrorJson so the maintenance UI shows a message instead of a 500.

Example fix

// before
var template = await _categoryTemplateService.GetCategoryTemplateByIdAsync(model.Id)
    ?? throw new ArgumentException("No template found with the specified id");
template = model.ToEntity(template);

// after
var template = await _categoryTemplateService.GetCategoryTemplateByIdAsync(model.Id);
if (template is null)
    return ErrorJson("This category template no longer exists.");
template = model.ToEntity(template);
Defensive patterns

Strategy: validation

Validate before calling

var template = await _categoryTemplateService.GetCategoryTemplateByIdAsync(model.Id);
if (template is null)
    return ErrorJson("Template no longer exists."); // abort update

Try / catch

try { await controller.CategoryTemplateUpdate(model); }
catch (ArgumentException ex) when (ex.Message.Contains("No template found"))
{ /* template deleted externally — reload list */ }

Prevention

When it happens

Trigger: Submitting a category-template edit form for a template that was deleted between the edit page load and the save. Posting a model with a stale or fabricated Id. Concurrent deletion by another maintenance session.

Common situations: An admin opens a category template for editing, leaves it idle, and another session deletes that template before the first saves. A maintenance/cleanup operation removed orphaned templates during a version upgrade.

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/e1590405faccc4ce. Report an issue: GitHub.