question

SSRS-VS avatar image
0 Votes"
SSRS-VS asked SSRS-VS edited

Cannot display Boostrap-Datepicker in asp.net-mvc Razor pages

I'm trying to implement an input datepicker in my asp.net-mvc project that display only years to create/edit new values of my model. I want the day and the month to be always the same (31/12/year) and allow the user to select only the year. Something like this:

104539-imagen.png

For that, I'm using the code from here: https://qawithexperts.com/article/bootstrap/select-only-year-in-bootstrap-datepicker/323

At the begginig, it didn't work:

104598-imagen.png

But lattely I found why. In the _layout.cshtml I have the default view when you create an asp.net-mvc project. And If I delete this: @Scripts.Render("~/bundles/jquery") It will work:

104540-imagen.png

But it is not correct to delete that since I need it for other things in other views. So my question is how to use the "only-year boostrap-datepicker" with @Scripts.Render("~/bundles/jquery") and why is this error happening?

Thank you.

dotnet-aspnet-core-mvcdotnet-aspnet-mvc
imagen.png (6.2 KiB)
imagen.png (6.9 KiB)
imagen.png (11.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ChaoDeng-MSFT avatar image
1 Vote"
ChaoDeng-MSFT answered ChaoDeng-MSFT edited

Hi @SSRS-VS ,
There is no need to delete @Scripts.Render("~/bundles/jquery"), you can do so.
If you do not need to use the layout view for the current page, you can set it to null.

 @{
     ViewBag.Title = "Index";
     Layout = null;
    
 }

Result:
dyysP.png

If you need to use the current layout view, you can do this.

Fgqnn.png

Result:
6zAHq.png



If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Best Regards,

ChaoDeng


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SSRS-VS avatar image
0 Votes"
SSRS-VS answered SSRS-VS edited

Thank you so much @ChaoDeng-MSFT Now it works.

Could you explain why that error happen before? Why do you need to put inside @section script hat one and not the other two? It is because some conflict withy @Scripts.Render("~/bundles/jquery")?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SSRS-VS ,
How is your code written, or the order of references to your files is not correct.
You can read this article, or it may be helpful to you.
https://exceptionnotfound.net/asp-net-mvc-demystified-layout-viewstart-renderbody-and-rendersection/


1 Vote 1 ·
SSRS-VS avatar image
0 Votes"
SSRS-VS answered SSRS-VS edited

Thanks @ChaoDeng-MSFT
My second question is how set the day and month from the script.

This is the new form for my model:
104708-imagen.png

And I want fix the day and month when I select the year:

104734-imagen.png

How can I set model=>Date.value = "31/12/" + selected year in the create and edit view so I can pass the value to the controller and pass de modelSatatet.isValid???

Date field in my model:

104761-imagen.png



imagen.png (25.5 KiB)
imagen.png (22.7 KiB)
imagen.png (4.4 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SSRS-VS,
If it is a new problem, I can suggest you to repost so that you can get better help.

1 Vote 1 ·