Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7886119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:14:20+00:00 2026-06-03T05:14:20+00:00

This Delete partial view is shown in a jquery dialog: When the delete view

  • 0

This Delete partial view is shown in a jquery dialog:

When the delete view is loaded in debug mode I see that the Model has a count of 3
but when I press the Delete button I get a NullReferenceException, that Model is Null.

How can that be?

@using (@Html.BeginForm("Delete","Template",FormMethod.Post))
{  
    <table>
    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Id)
            </td>  
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>      
            <td>           
                @Html.ActionLink("Delete", "Delete", new { id = item.Id, returnUrl = Request.Url.PathAndQuery })
            </td>
        </tr>
    }
    </table>
}

Controller:

  [HttpGet]
        public ActionResult Delete()
        {
            string actionName = ControllerContext.RouteData.GetRequiredString("action");
            if (Request.QueryString["content"] != null)
            {
                ViewBag.FormAction = "Json" + actionName;

                var list = new List<Template> {
                    new Template{ Id = 1, Name = "WorkbookTest"},
                    new Template{ Id = 2, Name = "ClientNavigation"},
                    new Template{ Id = 3, Name = "Abc Rolap"},
                    };

                return PartialView(list);
            }
            else
            {
                ViewBag.FormAction = actionName;
                return View();
            }
        }

 [HttpPost]
        public JsonResult JsonDelete(int templateId, string returnUrl)
        {
            // do I get here no !
            if (ModelState.IsValid)
            {
                return Json(new { success = true, redirect = returnUrl });
            }

            // If we got this far, something failed
            return Json(new { errors = GetErrorsFromModelState() });
        }

Update:

That code works and is supplying the correct templateId to the controller:

<table>
@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Id)
        </td>  
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>      
        <td> 
            @using (@Html.BeginForm((string)ViewBag.FormAction, "Template"))
            {
                @Html.Hidden("returnUrl", Request.Url.PathAndQuery);
                @Html.Hidden("templateId", item.Id)               
                <input type='submit' value='Delete' />
            }
        </td>
    </tr>
}
</table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:14:21+00:00Added an answer on June 3, 2026 at 5:14 am

    Judging from how your ActionLink is written, the else part of the controller is going to execute after you click delete (because content won’t be in the query string). That code returns View() with no model, hence the “model is null” exception.

    Edit

    There are 2 problems I can see:

    1. The action you’re targeting is requiring a POST, so you need to use a form postback and not an ActionLink (which uses GET).
    2. The action is expecting templateId, so the route attribute needs to be that.

    So I’m thinking this should work:

    @{ using (Html.BeginForm()) {
        <input type='hidden' name='templateId' value='@item.Id' />
        <input type='submit' value='Delete' />
    }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So right now I have a partial view that just has a list of
I have a pointer to a map that I am trying to delete (this
I am using a partial view that is displayed in a pop up to
Scenario: I have a View and inside that view I also a partial view.
I am loading a partial view into a page on a timer with jquery
Consider following: Partial View: <%= Html.ListBox(BlackList, Model.Select( x => new SelectListItem { Text =
I am rendering out a partial view like so: <div id=cart> <%Html.RenderPartial(Cart, Model); %>
I'm using MVC2 with jquery. I'm trying to open a partial view in a
I have a simple question. I have a model that looks like this: public
Let's explain the context: I have a person form inside a jquery dialog that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.