The New Way to Build with AI! Introducing ReUI — the developer platform for agentic UI with shadcn/ui
Browse ReUI Pro

daterangepicker not work when i use asp-for why and what is the solution


why not working and show problem in pkugin
<input type="text" class="form-control form-control-solid" placeholder="Publishing Date" id="kt_daterangepicker_3" asp-for="PublishingDate"/>

and js

$("#kt_daterangepicker_3").daterangepicker({
singleDatePicker: true,
showDropdowns: true,
autoUpdateInput: true,
autoApply: true,
drops: 'up',
maxDate: parseInt(moment().format("YYYY"), 12)

});


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (1)

Deleted comment
Deleted comment

Hi,

Understanding

The daterangepicker is not working when you add asp-for="PublishingDate" to the input element. This is a common issue when using ASP.NET Core tag helpers with Metronic's jQuery-based plugins.

Cause

The asp-for attribute generates the input with a different id and name attribute than what you specified. ASP.NET Core creates the id based on the model path (e.g., PublishingDate becomes ``), so the selector #kt_daterangepicker_3 may not match the rendered element.

Also, the maxDate option has a small bug:

maxDate: parseInt(moment().format("YYYY"), 12)

The radix should be 10, not 12.

Solution

Either match the generated id or use a class selector:

Option A — Match ASP.NET id:

$("#PublishingDate").daterangepicker({
  singleDatePicker: true,
  showDropdowns: true,
  autoUpdateInput: true,
  autoApply: true,
  drops: 'up',
  maxDate: parseInt(moment().format("YYYY"), 10)
});

Option B — Use a class and remove asp-for:

<input type="text" class="form-control form-control-solid daterangepicker-input"
       placeholder="Publishing Date"  />
$(".daterangepicker-input").daterangepicker({
  // ... same options
});

Option C — Use asp-for with a matching selector: Check your rendered HTML (view source) to see the actual id ASP.NET generated, then use that.

Sources


This reply was generated by AI. A human will follow up if needed.

Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
buy metronic keenthemes mega bundle

ReUI

Open-source React components, blocks and templates built on shadcn/ui and Tailwind CSS by Keenthemes.