Returning a PartialView with C# Razor Pages is causing an Error: Multiple constructors

I am trying for hours to return a Table as PartialView with the help of C# Razor Pages.
First i got the error the returning model is not equal to the expected model.
I changed the view model and the error was gone.
Now i got the Error:

InvalidOperationException: Multiple constructors accepting all given argument types have been found in type 'System.Collections.Generic.List`1[DantronikOrganizer.Data.Models.UserVacationEntity]'. There should only be one applicable constructor.

I start from the beginning:
I created a Index Page to show users there vacation requests in a table, but if they choose to delete an entry from the table, the entire page would be reloaded. So i though why not using ajax to solve this problem.

I deleted the table in my index page and created a new one in a _TableView.
Now an ajax request should load the view from _TableView into my index page.
Now when a user is deleted an entry from the table, only the table would be reloaded.
Thanks to the new PartialView.

I asked ChatGPT a lot about my problem, but even ChatGPT is not understanding why i get this error.

My Index View

@page
@model DantronikOrganizer.Pages.Vacation.IndexModel

@{
    ViewData["Title"] = "Urlaubsanträge";
}

<h1>Übersicht - Urlaubsanträge</h1>
<hr />

<p>
    <a class="btn btn-success" asp-page="VacationRequest">Urlaub beantragen</a>
</p>

<form>
    <div class="input-group mb-2 w-25">
        <input id="yearFilter" asp-for="@Model.FilterYear" class="form-control" placeholder="Nach Jahr filtern" aria-label="Filer by Year" aria-describedby="btnFilter">
        <button class="btn btn-outline-secondary" type="submit" id="btnFilter">Filtern</button>
    </div>
    <span asp-validation-for="@Model.FilterYear" class="text-danger"></span>
    <div class="form-check mb-2">
        <input id="approvedFilter" asp-for="@Model.FilterIsApproved" class="form-check-input" />
        <label class="form-check-label" asp-for="@Model.FilterIsApproved"></label>
    </div>
</form>
<hr />

<div class="row">
    <div class="col-lg-6">
        <h6>Ausgewähltes Jahr: </h6>
        <span class="text-primary">Urlaubstage: | Bisher genutzte: | Verfügbare: </span>
    </div>
</div>
<div id="partialViewContainer"></div>

<!--Modal Window to delete an entry in the table-->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="deleteModalLabel">Eintrag löschen</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                Möchten Sie wirklich den Eintrag löschen?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Abbrechen</button>
                <button type="button" class="btn btn-primary" id="deleteButton">Löschen</button>
            </div>
        </div>
    </div>
</div>

@section Scripts{
    <script>
        function showToast(message) {
            Toastify({
                text: message,
                duration: 5000,
                gravity: "top",
                position: "center",
                style: {
                    background: "#ff5722"
                },
                stopOnFocus: true
            }).showToast();
        }

        $(document).ready(function () {
            loadPartialView();
            $('#yearFilter, #approvedFilter').change(function () {
                loadPartialView();
            });
        });

        function loadPartialView() {
            var year = $('#yearFilter').val();
            var isApproved = $('#approvedFilter').is(':checked') || false;
            $.ajax({
                url: '@Url.Page("/Vacation/_TableView", "TableView")',
                data: { year: year, isApproved: isApproved },
                type: 'GET',
                success: function (data) {
                    $('#partialViewContainer').html(data);
                }
            });
        }

        function deleteVacation(id) {
            var token = $('input[name="__RequestVerificationToken"]').val();
            $('#deleteModal').modal('show');
            $('#deleteButton').on('click', function () {
                if (confirm("Möchten Sie wirklich den Eintrag löschen?")) {
                    $.ajax({
                        type: "POST",
                        url: "/Vacation/Delete?handler=delete",
                        data: { id: id, __RequestVerificationToken: token },
                        headers: { "RequestVerificationToken": token },
                        success: function (response) {
                            if (response.success) {
                                showToast(response.message);
                                loadPartialView();
                            }
                        },
                        error: function (response) {
                            if (response.error) {
                                showToast(response.message);
                            }
                        }
                    });
                    $('#deleteModal').modal('hide');
                }
            });
        }
    </script>
}

My PartialView Controller

using DantronikOrganizer.Areas.Identity.Data;
using DantronikOrganizer.Data.Interfaces;
using DantronikOrganizer.Data.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DantronikOrganizer.Pages.Vacation
{
    public class _TableView : PageModel
    {
        private readonly IUserVacation _service;
        private readonly UserManager<ApplicationUser> _userManager;
        public List<UserVacationEntity> UserVacationList { get; set; }
        public _TableView(IUserVacation service, UserManager<ApplicationUser> userManager)
        {
            _userManager = userManager;
            _service = service;
        }

        public async Task<IActionResult> OnGetTableView(int year, bool isApproved)
        {
            var user = await _userManager.GetUserAsync(User);
            UserVacationList = await _service.GetUserVacationByUser(user.Id);

            if (!string.IsNullOrEmpty(year.ToString()))
            {
                UserVacationList = UserVacationList.Where(u => u.DtFrom.Year == year).ToList();
            }

            if (isApproved)
            {
                UserVacationList = UserVacationList.Where(x => x.IsApproved).ToList();
            }
            return Partial("_TableView", UserVacationList);
        }
    }
}

My Partial View

@page
@model List<DantronikOrganizer.Data.Models.UserVacationEntity>
<table class="table table-hover">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(m => m[0].DtFrom)
            </th>
            <th>
                @Html.DisplayNameFor(m => m[0].DtUntil)
            </th>
            <th>
                @Html.DisplayNameFor(m => m[0].DaysRequested)
            </th>
            <th>
                @Html.DisplayNameFor(m => m[0].IsApproved)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @if (Model != null && Model.Any())
        {
            @foreach (var item in Model)
            {
            <tr>
                <td>@Html.DisplayFor(modelItem => item.DtFrom)</td>
                <td>@Html.DisplayFor(modelItem => item.DtUntil)</td>
                <td>@Html.DisplayFor(modelItem => item.DaysRequested)</td>
                <td>@Html.DisplayFor(modelItem => item.IsApproved)</td>
                <td>
                    <a class="btn btn-primary" asp-page="./Edit" asp-route-id="@item.Id">Bearbeiten</a> |
                    <a class="btn btn-primary" asp-page="./Details" asp-route-id="@item.Id">Details</a> |
                    <button class="btn btn-danger" onclick="deleteVacation(@item.Id)">Löschen</button>
                </td>
            </tr>
            }
        }
        else
        {
        <tr>
            <td colspan="5">No vacation entries found.</td>
        </tr>
        }
    </tbody>
</table>

Fetching data using ajax in a table

<!DOCTYPE html>
<html>
  <head>
    <title>Fetch data from API and display in table using AJAX</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  </head>
  <body>
    <h1>Data</h1>
    <table id="table" border="1"></table>

    <script>
      function load(){
        fetch("https://gorest.co.in/public/v2/users")
          .then(result => result.json)
          .then(json => show(json)) }
      function show(data){
      let table = document.getElementById('table');
      for(let i=0; i< data.length; i++){
        let obj = data[i];
        console.log(obj);
        let row = document.createElement('tr');
        let name = document. createElement('td');
        id.innerHTML = obj.
        row.appendChild(name)
        table.appendChild(row)
  }


}
    </script>
  </body>
</html>

I need to fetch data from a url. I have to present it in a table. First I only need to display username with a button “view more”. When view more will be clicked I have to fetch data from another api related to that particular username .I have written few line of code but they are not working. Any suggestionns? your text

Flow Based Visual Programming in Django

I am working with a Django Application for E-Commerce, where I have to build a visaul programming (Flow Based) feature. I came across two JS libraries RETE.JS and NODE-RED.

Node-RED is pretty powerfull tool, but it seem pretty difficult to integrate with Django application, as it is a node app. Also, I tried running it on port 1880 and loading it as <iframe>, which worked. But, still creating a lot of e-commerce custom nodes in NODEJS is big deal for me. (I am more into Python, Jquery, Normal Js but not in NODE.JS)

For retejs, there is no sidebar list of flow controls, meta fields for controls, like Node-Red already have.

Can you suggest some Open-Source JS based library which you help me develope some feature like in image attached. (Attached image is screenshot of feature from some company’s platform)

enter image description here

How to view (preview) excel file after upload in reactjs

When I upload excel file and convert it to url blob using URL.createObjectURL() and a button when onClick it will show my excel file. But instead of watching it download it.

here is my code:

const onUploadFile1 = (e) => {
    const file = e.target.files[0]

    setFile(file)
}

const onClickToView = () => {
    window.open(URL.createObjectURL(file), '_blank', 'noreferrer')
}

(*)I have used libraries to convert like xlsx, react-excel-renderer…but it’s not what I want because it breaks the layout of the file or when in excel there is an image it doesn’t display.

Can someone help me, the end goal I want is to view the excel file after uploading.
Thanks.

commit or dispatch inside a callback [duplicate]

I have a function in my vue/nuxt project to authorize a payment method, and inside de callback I need to execute a commit and a dispatch but the syntax apparently is not correct.
Any help will be appreciated.

myFunction () {
      window.client.Payments.authorize({
        payment_method_category: 'payments'
      }, {
        purchase_country: 'ES',
        purchase_currency: 'EUR',
        locale: 'es-ES',
        billing_address: {
        },
        shipping_address: {
        },
      },
      function (res) {
        if (res.approved) {
**        this.$store.commit('checkout/setMyFunctionAuthorizationToken', res.authorization_token)
          this.$store.dispatch('checkout/finish')
**        }
      })
    },

I can’t use the ‘this.$store’ but I don’t how to do it.

JS includes() returning partial matches

I have an string of numbers that we are comparing to ids in a json file with javascript to create a list of favorites. I am using includes() to test if the tourid in the json file is also in the string.

The issue shows up with larger numbers in the array. If the list contains 34, then the output shows only the details for tourid 34, but if 134 is in the list, then the output shows both tourid 34 and 134. I have also tried indexOf() with similar results.

Is there a way to force includes() to only go with exact matches?

The script is below (and yes it is in a worker script hence the postMessage ending):

function getMyLst(mylst) {
  // build nav list of based on myList array

  // check if mylst is empty of numbers
  if (mylst === '') {
    let myLstStr = 'rmvml|0';
    postMessage(myLstStr);
  }
  else {

    let xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
      if (this.readyState == 4 && this.status == 200) {
        var myLstStr = 'mylst|';
        var lstCnt = 0;
        var daLst = '';
        var clipList = '';
        data = JSON.parse(this.responseText);
        // loop through check if in mylst then build string
        for (let i = 0; i < data.length; i++) {
          if (mylst.includes(data[i].tourid)) {
            myLstStr += '<a href="'+data[i].url+'">'+data[i].tourname+'</a><br>';
            lstCnt++;
            daLst += (data[i].tourid)+',';
            clipList += data[i].tourname+' - '+data[i].url+'n';
          }
        }
        myLstStr += '|'+lstCnt+'|'+daLst.slice(0, -1)+'|'+clipList;
        postMessage(myLstStr);
      } 
    };

    xmlhttp.open("GET", dturl, true);
    xmlhttp.send();

  }
}

The worker onmessage function, with the value of mylst as sent to the worker as a comma separated string: mylst|146,57,134

onmessage = function (e) {

  // Determine worker function from first variable
  // strip first value before "|"
  let msg = e.data[0];
  var val = msg.split('|');

  // GO get myList data
  if (val[0] === 'mylst') {
    var mylst = val[1] ;
    getMyLst(mylst);
  }
  // end myList section

Why is the result of this code displaying NAN on submit?

Why is this js program not even doing a simple divison?
This is a js code for divison of two input numbers and displaying result on a submit.

<html>
<body>
<script>
    function divide(n1,n2)
    {
      try
      { num1=document.getElementById("n1").value;
        num1=document.getElementById("n1").value;
        var result=n1/n2;
        document.getElementById("result").innerHTML=result;
      }
      catch
      {
        document.getElementById("result").innerhtml=Error;
      }
    }
</script>
<form >
    N1:<input type="number" id="n1" name="n1" ></input><br>
    N2:<input type="number" id="n2" name="n2" ></input><br><br>
    <input type="SUBMIT" onclick="divide()" placeholder="Divide"></input><br><br>
</form>
    Result: <br><span id="result"></span>
</body>

How To Get UserName from url?

I want a username from a URL like “example.com/u/AbcUser”.
I know we can get it by using HTTP GET request, But I want to create a regular latest site

is it possible with Vanilla JS and HTML ??

Package does not provide default export

I am using an npm package in my test project, and it complains that caught SyntaxError: The requested module '/@fs/Users/package/module/index.js' does not provide an export named 'default' when using vite to build the project, but with webpack everything works just fine.

my tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "module": "ESNext",
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["src"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

and vite config

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
})

Having difficulty importing emscripten wasm c++ class into svelte component

I’ve been trying to use my c++ class in my svelte component, and been beating my head against the screen for the past week trying to figure out how to do this. I’m comfortable in c++ but not so much in JS, which I suspect is part of the issue.
My c++ code is :

#include <emscripten/emscripten.h>
#include <emscripten/val.h>
#include <emscripten/bind.h>

using namespace emscripten;
using emscripten::val;
using namespace std;
thread_local const val document = val::global("document");

class MyClass{
  private :
  val canvas;
  val ctx;
  public :
MyClass(std::string id){
  canvas = val::global("document").call<val>("getElementById", val(id));
  ctx = canvas.call<val>("getContext", val("2d") );}

void greenRect(){
   emscripten_run_script("alert('greenrect')");
   ctx.set("fillStyle", "green");
   ctx.call<void>("fillRect", 10, 10, 150, 100);
 }
 ~MyClass(){}};

  EMSCRIPTEN_BINDINGS(MyClassModule) {
   class_<MyClass>("MyClass")
     .constructor< std::string>()
     .function("greenRect", &MyClass::greenRect)
     ;}

In this example my life would probably be easier if I just switched to a C++ function rather than a class, but I would like to keep it as a class unless this is completely non-viable (which it shouldn’t be).
My current invocation of the compiler is em++ -s ALLOW_MEMORY_GROWTH=1 -lembind -s USE_SDL=2 -s ENVIRONMENT='web' -s SINGLE_FILE=1 chart.cpp -o glue.js

The script portion of the App.svelte component is

  import { onMount } from "svelte";
  import { MyClass } from "../em/glue.js";
  onMount(async () => {
    alert("pre");
    const chart = new Module.MyClass("canvas0");
    alert("post");
    chart.greenRect();
  });

I get the “pre” popup but never the “post” popup.

I’ve tried several variations on the import statement with import MyClass from 'glue.js', <script src ="glue.js"> in the svelte:header section. I’ve also tried a variety of CLI options including-s MODULARIZE=1, -s EXPORT_ES6=1,-s EXPORT_ALL=1, -s WASM=1 none of which seem to fix this issue.

The problem is that I keep getting errors in the browser
import { MyClass } from 'glue.js' -> “Uncaught SyntaxError: ambiguous indirect export: MyClass”
import * as MyClass from 'glue.js' -> Uncaught (in promise) TypeError: Module.MyClass is not a constructor
import MyClass from 'glue.js' -> Uncaught SyntaxError: ambiguous indirect export: default
I’ve also changed the const chart = new MyClass("canvas0") to const chart = new Module.MyClass("canvas0"); and const chart = new MyClass.MyClass("canvas0");

Yup, JS is not my strong point and I’m admittedly just throwing stuff at the wall to see what sticks.

If someone could point me in the right direction I’d really appreciate it. I tried to get chatGPT and Bard to fix the issue and have come away feeling confident that coders’ jobs are secure for the foreseeable future.

I appreciate any help you can give.
Thanks