简体   繁体   中英

Invalid regular expression flags error Partial View

I have div in my View that upload PartialView.

Here is code

<div id="right2" style=" border-style: solid; border-color: #1d69b4; border-radius: 10px;"> @Html.Partial("CalendarDefault") </div>

And by button I need to change one PartialView to another

here is button code

<button class="filled-button" onclick="myFunction()" style="background: #72c367">New Appointment</button>

And JS code for load

<script>
function myFunction() {
    $("#right2").load(@Url.Action("SheduleNewAppointment","Calendar"));
}
</script>

But I have below errors

myFunction is not defined at HTMLButtonElement.onclick (Index:125) Uncaught SyntaxError: Invalid regular expression flags

How I can fix it?

This is example work for me:

Here is the code that I have created in my cshtml file:

    <script>
        $('#getDetails')
            .click(function() {
                $('#detailsPlace').load('@Url.Action("GetDetails", "Home")');
            });
    </script>

<table class="table">
    @foreach (var item in Model)
    {
        <tr>
            <td>
                <a href="#" id="getDetails">@Html.DisplayFor(modelItem => item.Description)</a>
            </td>
        </tr>
    }
</table>

<div id="detailsPlace"></div>

/Home/GetDetails is being interpreted as a regular expression, using "Home" as the pattern and "GetDetails" as the flags. That's an invalid regular expression, hence the error.

This is the code inside my contoller:

[HttpGet]
    public ActionResult Index()
    {
        ReferenceRepository test = new ReferenceRepository();

        var response = test.GetParts("A");
        return View(response);
    }
public ActionResult GetDetails()
    {
        return PartialView();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM