0

I want to delete the record of employee using Post Method. I replaced the html.Actionlink with button. I also want to prompt user for confirmation before deleting the record.
I have written following code:

<input value="Delete" type="submit" onclick="return confirm('Are you sure want to delete ID = @item.EmpId');"/>

This line is showing error "unterminated string constant", what's wrong in this code?

my complete view code

<table border="1">
    <tr>

        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Gender)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.City)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DID)
        </th>
        <th>Action
        </th>

    </tr>

    @foreach (var item in Model)
    {
        using (Html.BeginForm("Delete", "Employee",new{id=item.EmpId}))
        {
        <tr>

            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Gender)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.City)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.DID)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.EmpId }) |
                @Html.ActionLink("Details", "Details", new { id = item.EmpId }) |

                <input value="Delete" type="submit" onclick="return confirm('Are you sure want to delete ID = @item.EmpId');"/>
            </td>
        </tr>
        }
    }

</table>
7
  • Can you post the complete code of your view? At least the part where @item is defined Commented Apr 28, 2014 at 17:26
  • Are you sure the error is on that line? Commented Apr 28, 2014 at 17:35
  • yes sir , when i remove that javascript code , then there is no error Commented Apr 28, 2014 at 17:36
  • perhaps there is no error when you pull out that onclick but since it seems valid maybe something previous to that is causing it to throw an error there. What does the rendered Edit & Details links look like? Also are you actually getting your @item.EmpId rendered in your onclick or are the quotes around it keeping it from being processed? Commented Apr 28, 2014 at 17:45
  • actually it is because of js quotes Commented Apr 28, 2014 at 17:48

1 Answer 1

-1

Just run the application.let the error be there. You wont get any error at complile or run time.It will run as expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.