User Profile
AddWebSolution
Brass Contributor
Joined 3 years ago
User Widgets
Recent Discussions
Re: How to handle Exceptions in VBHTML Razor page?
HI Malam115 , Yes, you can add exceptions to the VBHTML Razor page. Here are your problem solutions. https://stackoverflow.com/questions/76996606/how-to-catch-exception-thrown-in-asp-net-core-razor-page-middleware Thanks & BestRegards, AddWebsolution381Views0likes0CommentsRe: MVC Controller Method Overloading
Hi DSK Chakravarthy, The correct syntax for route constraints in ASP.NET Core is different from what you have in your code. Route constraints are typically defined using curly braces {}. Here's the corrected version of your code: public class YourController : Controller { [Route("YourController/GetSomeData/{input:int}")] public ActionResult GetSomeDataByInt(int input) { // Route detection with the input parameter and change the functional flow for INT data type } [Route("YourController/GetSomeData/{input}")] public ActionResult GetSomeDataByString(string input) { // Route detection with the input parameter and change the functional flow for STRING data type } } Make sure to use {input:int} and {input} instead of just int and leaving it as is. This syntax informs ASP.NET Core that you are defining a route parameter named input with a constraint of type int for the first method and without any constraint for the second method. Regarding the second part of your question about MVC Controller Method Overloading, in ASP.NET Core, method overloading is not directly supported for action methods. You typically rely on route templates and route parameters to distinguish between different actions. If you want to handle different data types differently, you should use route constraints as shown in your first code snippet. However, make sure to use the correct syntax as provided above. If you are using .NET Framework 4.5.2 with MVC, then the route attributes and syntax may be different, and you may not have the same level of flexibility and features as ASP.NET Core. Please check the documentation for the version you are using for the correct syntax. Thanks & Best Regards, AddWebSolution1.9KViews0likes0CommentsRe: Create toolbar .NET Core
Hi jareyes, You can refer to below link https://ej2.syncfusion.com/aspnetcore/documentation/toolbar/getting-started And also give you an example of the toolbar 1. To create a toolbar in an ASP.NET Core application that includes buttons for actions like New, Update, Create, and Delete, you can use a combination of partial views, tag helpers, and Razor syntax. Here's a step-by-step guide: Create a Partial View for the Toolbar: Create a new partial view file (e.g., _Toolbar.cshtml) in the Views/Shared folder. <!-- Views/Shared/_Toolbar.cshtml --> <div class="toolbar"> <button onclick="location.href='@Url.Action("Create", ViewContext.RouteData.Values)"">New</button> <button onclick="location.href='@Url.Action("Update", ViewContext.RouteData.Values)"">Update</button> <button onclick="location.href='@Url.Action("Delete", ViewContext.RouteData.Values)"">Delete</button> <!-- Add more buttons as needed --> </div> Include the Partial View in the Layout (_Layout.cshtml): Include the toolbar partial view in your layout file. <!-- Views/Shared/_Layout.cshtml --> <!DOCTYPE html> <html> <head> <!-- Your head content --> </head> <body> <div class="container"> <!-- Include the toolbar partial view --> @await Html.PartialAsync("_Toolbar") <!-- Main content --> <main> @RenderBody() </main> </div> </body> </html> 2. Access Controller, Action, and Model in the Toolbar: To access the current controller, action, and model, you can use the ViewContext property and RouteData dictionary. <!-- Views/Shared/_Toolbar.cshtml --> <div class="toolbar"> <button onclick="location.href='@Url.Action("Create", ViewContext.RouteData.Values)"">New</button> <button onclick="location.href='@Url.Action("Update", ViewContext.RouteData.Values)"">Update</button> <button onclick="location.href='@Url.Action("Delete", ViewContext.RouteData.Values)"">Delete</button> <div> <strong>Controller:</strong> @ViewContext.RouteData.Values["controller"]<br /> <strong>Action:</strong> @ViewContext.RouteData.Values["action"]<br /> @if (ViewContext.ViewData.Model != null) { <strong>Model Type:</strong> @ViewContext.ViewData.Model.GetType().FullName } </div> <!-- Add more buttons as needed --> </div> 3. Styling (Optional): Add some styling to make your toolbar visually appealing. /* Add your CSS in a separate file or in the head of your layout */ .toolbar { background-color: #f2f2f2; padding: 10px; margin-bottom: 20px; } .toolbar button { margin-right: 10px; } This example assumes that you have a basic understanding of ASP.NET Core MVC and Razor syntax. The toolbar will appear on all pages that use the layout file. The Url.Action method is used to generate URLs for the specified controller actions dynamically. Remember to customize the buttons and styling according to your application's requirements. Thanks & Best Regards, AddWebSolution560Views0likes0CommentsRe: Trouble with WebForms app
Hi jaakivask, In a WebForms application, you can declare and use variables in the code-behind file associated with the corresponding .aspx page. Since you mentioned that you do not have access to the code-behind source file, you may face limitations in making such changes. However, I'll provide guidance on where you would typically declare a variable in the code-behind file. Locate the Code-Behind File: The code-behind file is associated with the .aspx page and usually has the same name as the .aspx page with a ".aspx.cs" or ".aspx.vb" extension for C# or VB.NET, respectively. Add a Variable Declaration: Open the code-behind file in a code editor. Inside the class associated with the .aspx page, you can declare a variable. For example, you can declare the variable at the class level to make it accessible throughout the class. public partial class YourPageName : System.Web.UI.Page { // Declare a variable at the class level private string productVariantName; // Other code... // Event handler or method where you want to assign a value to the variable protected void Page_Load(object sender, EventArgs e) { // Assign a value to the variable productVariantName = ((OrderProductVariant)Container.DataItem).ProductVariant.Name; // Other code... } // Other methods or event handlers... } Use the Variable in Your Markup: Once the variable is declared at the class level, you can use it in your markup within the .aspx file. <p style="font-family:Arial;font-size: 9pt;color:black" class="bla"> <%# ProductService.GetProductVariantName((OrderProductVariant)Container.DataItem, LanguageId) %> <strong> <%# (productVariantName == "Kuldne keskmine" || productVariantName == "Aukso vidurys") && ((OrderProductVariant)Container.DataItem).ProductVariant.Product.TemplateId == 4 ? "GĖLIŲ VAZA" : (productVariantName == "Luksuslik" || productVariantName == "Deluxe") && ((OrderProductVariant)Container.DataItem).ProductVariant.Product.TemplateId == 4 ? "GĖLIŲ VAZA" : "" %> </strong> </p> Remember to replace "YourPageName" with the actual name of your .aspx page, and make sure to save your changes and recompile the application. If you don't have access to the code-behind file, you might need to work with the development team or the person responsible for maintaining the code to make these modifications. Here you can refer the link also https://stackoverflow.com/questions/4029467/broken-link-between-aspx-and-aspx-cs-files Thanks & Best Regards, AddWebSolution387Views0likes0CommentsRe: Uniform way of using environment variables in development and production
Hi @jKingNinja, you can try this : string connectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION_STRING"); OR string connectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION_STRING") ?? Configuration.GetSection("ConnectionStrings:DefaultConnection").Value; Here you can find the reference also, https://learn.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariable?view=net-8.0 Thanks & Best Regards, AddWebSolution515Views0likes0CommentsRe: MVC Controller Method Overloading
Hi DSK Chakravarthy, In ASP.NET MVC, method overloading based on input parameters directly in the way you're describing isn't supported. The framework uses the method name to route the request to the corresponding action, and it doesn't consider the parameters for method selection. If you want to achieve different behavior based on the input parameters, you have a few options: 1. ActionName Attribute: As you mentioned, you can use the ActionName attribute to specify different names for your actions. This allows you to have multiple actions with different parameters. public class YourController : Controller { public ActionResult GetSomeData() { // Default execution for given route } [ActionName("GetSomeDataByInt")] public ActionResult GetSomeData(int inputValue) { // Route detection with the input parameter and change the functional flow for INT data type } [ActionName("GetSomeDataByString")] public ActionResult GetSomeData(string inputString) { // Route detection with the input parameter and change the functional flow for STRING data type } } 2. Use a Single Action with Nullable Parameters: Combine all your logic into a single action with nullable parameters and handle the logic based on the provided values. public class YourController : Controller { public ActionResult GetSomeData(int? inputValue, string inputString) { if (inputValue.HasValue) { // Route detection with the input parameter and change the functional flow for INT data type } else if (!string.IsNullOrEmpty(inputString)) { // Route detection with the input parameter and change the functional flow for STRING data type } else { // Default execution for given route } } } 3. Use Route Constraints: You can define route constraints to guide the routing based on parameter types. However, this might not be as flexible as you want. public class YourController : Controller { [Route("YourController/GetSomeData/{input:int}")] public ActionResult GetSomeDataByInt(int input) { // Route detection with the input parameter and change the functional flow for INT data type } [Route("YourController/GetSomeData/{input}")] public ActionResult GetSomeDataByString(string input) { // Route detection with the input parameter and change the functional flow for STRING data type } } Choose the approach that best fits your requirements and design preferences. Thanks & Best Regards, AddWebSolution2.1KViews1like2CommentsRe: MVC Controller Method Overloading
Hi DSK Chakravarthy, Please refer this below article it will give you clear idea about the method overloading. Here is the solution, https://www.ifourtechnolab.com/blog/overloading-action-method-in-asp-net-mvc#:~:text=Method%20Overloading%20in%20MVC,-When%20we%20try&text=It%20simply%20does%20not%20know,value%20of%20address%20or%20name. Thanks & Best regards, AddWebSolution2.3KViews1like4CommentsRe: Upgrade .Net Framework 4.7.2 Solution to .Net 8
Hi Sam_Developer , https://www.google.com/search?q=how+to+upgrade+4.7.2+to+8+in+dot+net+core&rlz=1C1ONGR_enIN1030IN1030&oq=how+to+upgrade+4.7.2+to+8+in+dot+net+core&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIJCAEQIRgKGKABMgkIAhAhGAoYoAHSAQg0NTEzajBqN6gCALACAA&sourceid=chrome&ie=UTF-8#fpstate=ive&vld=cid:c56e3cf7,vid:3mPb4KAbz4Y,st:0 Best Regards, AddWebSolution2.2KViews1like0CommentsRe: Sync Issue in .NET Application
Hi sanchit1802, Here is your problem solution. In .NET, you typically don't need to explicitly call the `sync` method to ensure data is written to disk. The operating system handles this for you through its file-caching mechanisms. However, if you have specific requirements where you need to ensure data is written to disk immediately, there are a few options you can consider: 1. FileOptions.WriteThrough: - When opening a file, you can use the `FileOptions.WriteThrough` flag to bypass the OS cache. This forces every write to go directly to the disk. However, this can be slower because it bypasses the OS's optimizations. Example: using (FileStream fs = new FileStream("myfile.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 4096, FileOptions.WriteThrough)) { // Write data to the file } 2. File.Flush: - The `FileStream.Flush` method ensures that all buffered data is sent to the file, but it doesn't guarantee that the data is written all the way to the disk. It depends on the OS's behavior. Example: using (FileStream fs = new FileStream("myfile.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { // Write data to the file fs.Flush(); } 3. FileStream.ForceFlush: - In .NET 6 and later versions, there's a new method `ForceFlush` introduced in the `FileStream` class. This method provides a stronger guarantee that data is flushed to disk. Example: using (FileStream fs = new FileStream("myfile.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { // Write data to the file fs.ForceFlush(); } Remember, while these methods provide ways to exert more control over the write operations, they can come at the cost of performance. It's generally advisable to rely on the OS's caching mechanisms unless you have a specific reason to do otherwise. Also, be aware that in most scenarios, the operating system's caching mechanisms are highly optimized and calling `sync` or similar methods directly is usually unnecessary and can even degrade performance. It's important to thoroughly test and profile your application to determine if explicit syncing is really necessary for your specific use case. Best Regards, AddWebSolution355Views0likes0CommentsRe: Teacher, new to .NET
Certainly! It's great that you're interested in using .NET for this project. Here are some resources and modules that can help you get started: 1. ASP.NET Core : - This is a popular framework for building web applications with .NET. - [ASP.NET Core Documentation](https://docs.microsoft.com/en-us/aspnet/core/😞 This is the official documentation and it's very comprehensive. 2. Entity Framework Core : - This is an Object-Relational Mapping (ORM) framework for .NET. It will help you interact with databases in a more natural way. - [Entity Framework Core Documentation](https://docs.microsoft.com/en-us/ef/core/😞 Official documentation for Entity Framework Core. 3. Authentication and Authorization : - For secure logins, you'll want to look into the built-in authentication and authorization features in ASP.NET Core. - [ASP.NET Core Authentication and Authorization](https://docs.microsoft.com/en-us/aspnet/core/security/😞 This section of the documentation will be very helpful. 4. Azure for Hosting : - If you're interested in hosting your application on Azure, you'll want to learn about Azure App Service. - [Azure App Service Documentation](https://docs.microsoft.com/en-us/azure/app-service/😞 This will guide you through the process of deploying your application. 5. Adding Family Members : - To add family members, you'll need forms and likely some kind of admin panel. - For forms, you can use HTML along with ASP.NET Core's Tag Helpers. - For an admin panel, you can create a separate area or page that's password protected. 6. Database : - You'll need to decide on a database. SQL Server is a common choice and integrates well with .NET. - [SQL Server Documentation](https://docs.microsoft.com/en-us/sql/sql-server/😞 This is the official documentation. 7. Learning Paths and Tutorials : - [Microsoft Learn](https://learn.microsoft.com/en-us/😞 This is Microsoft's official learning platform. It has a variety of tutorials and learning paths. 8. Sample Projects and Templates : - [ASP.NET Core Samples](https://github.com/dotnet/AspNetCore.Docs😞 This GitHub repository contains a variety of sample projects that can help you understand how things work. 9. Community Forums : - [Stack Overflow](https://stackoverflow.com/questions/tagged/asp.net-core😞 You can ask specific questions here and get help from the community. Remember, building a web application with databases and secure authentication is a multi-step process. It's often helpful to break it down into smaller tasks and tackle them one at a time. Good luck with your project, and feel free to ask if you have any specific questions along the way! Best Regards, AddWebSolution653Views0likes0CommentsRe: translate validation message Modal form using ressource file c# not working on server
Hi wissDev, Here you get the solution: https://learn.microsoft.com/en-us/previous-versions/aspnet/bz9tc508(v=vs.100) OR You can also check the below points: It seems like you're experiencing an issue with the validation message localization when deploying your ASP.NET MVC C# project. Here are some steps you can take to troubleshoot and resolve the issue: 1. Check Resource File Names and Locations: - Make sure that your resource files are named correctly and are located in the appropriate folders (e.g., `Resources` or `App_GlobalResources`). 2. Check Deployment Environment: - Ensure that the server environment supports localization. This includes making sure that the appropriate .NET Framework or .NET Core runtime is installed. 3. Verify Resource File Deployment: - Double-check that your resource files have been deployed along with your application to the server. 4. Verify Culture Settings: - Ensure that the server's culture settings are correctly configured. This can be done in the server's control panel or through server-wide settings. 5. Check Web.Config: - In your `Web.config`, ensure that globalization settings are configured correctly. This includes the `culture` and `uiCulture` attributes in the `<system.web>` section. <system.web> <globalization culture="auto" uiCulture="auto" /> </system.web> 6. Check for Missing Resource Files: - Confirm that both resource files (for English and French) are present on the server. 7. Verify Resource Access Permissions: - Ensure that the application pool identity or user account running the application has appropriate permissions to access the resource files. 8. Check Server Error Logs: - Review server logs for any error messages related to resource file access or localization. 9. Rebuild and Redeploy: - Clean and rebuild your project, then redeploy it to the server. 10. Check File Encoding: - Ensure that the resource files are encoded properly. UTF-8 encoding without BOM is typically recommended. 11. Check for Case Sensitivity: - Some servers may be case-sensitive, so make sure that the file names are referenced with the correct casing. 12. Clear Server Cache: - If applicable, clear any server-side caching mechanisms that might be storing old versions of the resource files. 13. Test on a Different Server: - If possible, try deploying the application on a different server to see if the issue persists. This can help isolate whether the problem is specific to the server environment. Remember to back up your files before making any changes, and consider testing changes in a non-production environment first. If the issue persists, you may need to consult with your hosting provider or system administrator for further assistance.827Views0likes0CommentsRe: Capturing data of 1 page in another page using razor view and dotnet core
Hi Bioku, To achieve this, you can use TempData in ASP.NET Core to temporarily store and pass data between actions. 1) First Page (Input Page) In your Razor view, make sure you have a form that collects the Name, Email, and Career. When the form is submitted, it will POST to an action in your controller. <form method="post" asp-action="RegisterMentee"> <input type="text" name="Name" /> <input type="text" name="Email" /> <select name="Career"> <!-- Populate options from your database or enum --> </select> <input type="submit" value="Next" /> </form> 2) Controller Action for First Page In your controller, have an action that handles the form submission. Store the data in TempData. [HttpPost] public IActionResult RegisterMentee(string Name, string Email, string Career) { TempData["Name"] = Name; TempData["Email"] = Email; TempData["Career"] = Career; return RedirectToAction("ChooseMentor"); } 3) Second Page (Choose Mentor Page) In the Razor view for the second page, display the list of mentors for the selected career. Each mentor should have a button that allows the mentee to select them. @foreach(var mentor in mentorsForSelectedCareer) { <div> <span>@mentor.Name</span> <form method="post" asp-action="SelectMentor"> <input type="hidden" name="MentorId" value="@mentor.Id" /> <input type="submit" value="Select Mentor" /> </form> </div> } 4)Controller Action for Second Page In the controller, handle the mentor selection and retrieve the data from TempData to associate with the mentee. [HttpPost] public IActionResult SelectMentor(int MentorId) { // Retrieve data from TempData string Name = TempData["Name"] as string; string Email = TempData["Email"] as string; string Career = TempData["Career"] as string; // Create and save the mentee record Mentee newMentee = new Mentee { Name = Name, Email = Email, Career = Career, MentorId = MentorId }; // Save the mentee to the database return RedirectToAction("SuccessPage"); } Note that in this step, you should replace Mentee with the actual model class you're using and adjust the code to interact with your database. This way, you're using TempData to temporarily store the data between the two actions. When the mentee selects a mentor, you can retrieve the data from TempData and associate it with the mentee before saving them to the database. Best Regards, AddWebSolution1.4KViews0likes0CommentsRe: XSL Transform
Hi BeBor1426 Thank you for the posting here, Here is your problem's solution!! In your HTML file, you're using <link> to reference the XSLT stylesheet. This is incorrect. Instead, you should use the <?xml-stylesheet?> processing instruction to link the XSLT file. Here's the corrected HTML code: <!DOCTYPE html> <html> <head> <title>My Catalog</title> <link rel="stylesheet" href="styles.css"> <?xml-stylesheet type="text/xsl" href="myindex.xsl"?> </head> <body> <h1>HTML Heading</h1> <p>HTML paragraph.</p> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> </catalog> </body> </html> In your XSLT file, there's a typo in the opening <?XSL/Transforml ... ?> tag. It should be <?xml-stylesheet ... ?> instead. Also, there's a small issue with your XPath expressions in the <xsl:for-each> loop. It should be <xsl:value-of select="title"/> and <xsl:value-of select="artist"/>. Here's the corrected XSLT code: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CDs</h2> <table border="1"> <tr bgcolor="#9acd32"> <th style="text-align:left">Title</th> <th style="text-align:left">Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Make sure that both index.html and myindex.xsl are in the same directory, and then try opening index.html in your web browser again. It should now apply the XSLT transformation correctly. Best Regards, AddWebSolution821Views0likes0CommentsRe: "Thread was interrupted from a waiting state" from DbConnectionPool.CleanupCallback
Hi Pedro-Goncalves, Thanks for posting your issue here. Here is the solution of your problems: https://stackoverflow.com/questions/35979245/vb-net-does-sqlconnection-get-closed-automatically-in-a-try-catch-if-exception-i let me know if you have any query on this. Best Regards, AddWebSolution3KViews1like1Comment
Recent Blog Articles
No content to show