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 8171819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:34:53+00:00 2026-06-06T21:34:53+00:00

I use MVC 3, I have a controller with the following code, I cannot

  • 0

I use MVC 3, I have a controller with the following code, I cannot get the ViewModel [HttpPost] ActionResult Delete the AdvSlotDeleteViewModel result NULL, I have a similar Action Method for Edit and it is working, Could you help me out on this problem?

// GET: /ManageAdvSlots/Delete/5

    public ActionResult Delete(int id)
    {
        AdvSlot advSlot = advSlotRepository.FindById(id);
        AdvSlotDeleteViewModel deleteViewModel = Mapper.Map<AdvSlot, AdvSlotDeleteViewModel>(advSlot);
        return View(deleteViewModel);
    }

    //
    // POST: /ManageAdvSlots/Delete/5

    [HttpPost]
    public ActionResult Delete(AdvSlotDeleteViewModel deleteViewModel)
    {
        if (ModelState.IsValid)
        {
            AdvSlot advSlot = Mapper.Map<AdvSlotDeleteViewModel, AdvSlot>(deleteViewModel);
            advSlotRepository.Delete(advSlot.AdvSlotId);
            advSlotRepository.Save();
        }
        return RedirectToAction("Index");
    }
}

VIEW

@model MyProject.ViewModels.AdvSlotDeleteViewModel

@{
    ViewBag.Title = "Delete";
}

<h2>Delete</h2>

<h3>Are you sure you want to delete this?</h3>
<fieldset>
    <legend>AdvSlotDeleteViewModel</legend>

    <div class="display-label">AdvSlotId</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.AdvSlotId)
    </div>

    <div class="display-label">Name</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Name)
    </div>

    <div class="display-label">Description</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Description)
    </div>

    <div class="display-label">IsPublished</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.IsPublished)
    </div>

    <div class="display-label">Code</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Code)
    </div>

    <div class="display-label">Note</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Note)
    </div>
</fieldset>
@using (Html.BeginForm()) {
    <p>
        <input type="submit" value="Delete" /> |
        @Html.ActionLink("Back to List", "Index")
    </p>
}

VIEW MODEL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyProject.ViewModels
{
    public class AdvSlotDeleteViewModel
    {
        public int AdvSlotId { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public bool IsPublished { get; set; }
        public string Code { get; set; }
        public string Note { get; set; }
    }
}
  • 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-06T21:34:55+00:00Added an answer on June 6, 2026 at 9:34 pm

    What people are suggesting is sufficient is to include just the id in a hidden form field:

    @using (Html.BeginForm()) {
    @Html.HiddenFor(x => x.AdvSlotId)
    <p>
        <input type="submit" value="Delete" /> |
        @Html.ActionLink("Back to List", "Index")
    </p>
    }
    

    You may find that you don’t want to check if the model is valid any more. If you have advanced validation on some of the fields, if they’re not inside the form they won’t be posted back. For instance if “Name” is required, it will fail validation with the above code because only fields inside the form are posted back to the server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in my zf2 controller: <?php namespace Accounting\Controller; use Zend\Mvc\Controller\ActionController,
I want to use MEF with asp.net mvc. I wrote following controller factory: public
i have the following code in c#. I'm using ASP.NET MVC 3. public override
If I have following code in my controller: $this->view->print = <form method='{$method}'> //Some form
Following on from this question: ASP.NET MVC Routing with Default Controller I have a
I have 2 attributes that I use within the controllers of my MVC application.
I use declarative roles in my MVC.NET controllers and I have a custom membership
I use MVC 3 and EF 4.3.1. I have my class created with POCO
I have MVC application configured to use Forms Authentication. I'm signing out users by
I have learned how to use Spring MVC 3, but I am very interested

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.