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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:13:46+00:00 2026-05-16T01:13:46+00:00

When I press the submit button and access the Controller my ViewModel is empty.

  • 0

When I press the submit button and access the Controller my ViewModel is empty. I don’t know why this is happening, I have similar code to this on the other views and they do pass through data.

Controller

        public ActionResult DeleteCategory(int id)
        {
            var data = _service.GetIndividualCategory(id);
            if (data == null) return View("NotFound");

            // If attached to traders send to other view
            var traders = _service.GetTradersAttachedToCategory(id);
            if (!traders.Any())
            {
                var category = new DeleteCategoryViewModel
                {
                    Description = data.Description,
                    Id = data.Id
                };

                return View(category);
            }

            var trader = new DisplayTradersAttachedToCategoryViewModel
            {
                Description = data.Description,
                Id = data.Id,
                BusinessName = traders.Select(x => new BusinessNameViewModel { BusinessName = x.BusinessName, Id = x.Id }),
                Categories = _service.GetCategories(id).Select(x => new SelectListItem {Text = x.Description, Value = x.Id.ToString()})
            };

            return View("DeleteCategoryAttachedToTraders", trader);
        }

Accessed when ‘Submit’ button hit

       [HttpPost]
        public ActionResult DeleteCategoryFromTradersAttachNewCategory(DisplayTradersAttachedToCategoryViewModel displayTradersAttachedToCategoryViewModel)
        {
            if (displayTradersAttachedToCategoryViewModel.Button == "Back to List") return RedirectToAction("ViewCategories");

            //Update traders with new category
            //delete category

            //if (_service.DeleteCategory((int)deleteCategoryViewModel.Id))
            //{
            //    return RedirectToAction("ViewCategories");
            //}

            return View("DeleteCategoryAttachedToTraders", displayTradersAttachedToCategoryViewModel);
        }

DeleteCategoryAttachedToTraders.aspx

<%@ Page Title="Delete Category - Traders Attached to Category" Language="C#" MasterPageFile="~/Views/Shared/Master.Master" Inherits="System.Web.Mvc.ViewPage<Internal.ViewModels.Controller.DisplayTradersAttachedToCategoryViewModel>" %>

<asp:Content ID="pageTitle" ContentPlaceHolderID="PageTitle" runat="server">
  Delete Category - Traders Attached to Category
</asp:Content>

<asp:Content ID="htmlHead" ContentPlaceHolderID="HtmlHead" runat="server">
  <link href="<%=ResolveUrl("~/Assets/Styles/CSS.css")%>" rel="Stylesheet" type="text/css" />
</asp:Content>

<asp:Content ID="bodyContent" ContentPlaceHolderID="BodyContent" runat="server">
  <div class="center"><%
    using (Html.BeginForm("DeleteCategoryFromTradersAttachNewCategory", "Controller",FormMethod.Post))
    {%>    
      <h2>Delete Category - Traders Attached to Category</h2>
      <div class="magiPadBig"></div>

      <div class="magiPadBig"></div>      
      <%=Html.DisplayFor(x => x.BusinessName)%>

      <div class="magiPadBig"></div>   
      <h3>New Category</h3>

      <div class="magiPadBig"></div>    
      <%=Html.DropDownList("Categories")%>

      <div class="magiPadBig">  
        <input type="submit" name="Button" value="Back to List" />
        <input type="submit" name="Button" value="Submit" />
      </div><%
    }%>
  </div>
</asp:Content>  

DisplayTradersAttachedToCategoryViewModel

public class DisplayTradersAttachedToCategoryViewModel
{
    public int Id { get; set; }
    public string Description { get; set; }

    [UIHint("BusinessNameDisplayTemplate")]
    public IEnumerable<BusinessNameViewModel> BusinessName { get; set; }

    public IEnumerable<SelectListItem> Categories { get; set; }

    public int Category { get; set; }

    public string Button { get; set; } 
}

Thanks in advance for any help.

Clare

  • 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-05-16T01:13:47+00:00Added an answer on May 16, 2026 at 1:13 am

    The problem I can see (and I fully expect others to correct me here) is the following:
    (edited for clarity)

    1. Id won’t be set because you are posting to a different form, and there is no hidden field for the ID, so it won’t be set.
    2. Description won’t be set, as there is nothing for it to be set from.
    3. Categories won’t be set, because the Ienumerable is populated only in your get, and not your post (which is fair enough, as you aren’t posting the whole list).
    4. Category isn’t populated because you’ve named the drop down list “Categories”, and so it won’t match the name “Category” in the viewmodel.

    Try

    <%=Html.DropDownList("Category", Model.Categories)%>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have some code which when you press the submit button, a marker
/* listen for the submit button press */ YAHOO.util.Event.addListener(webserver.result_form, 'submit', webserver.result_submit); I have this
In Firefox 4 when I press submit button nothing happens. The code of button
If we have several forms like below and when i finally press submit button,
VIDEO OF PROBLEM: http://www.youtube.com/watch?v=Y6RZHMQueDc&feature=youtu.be When i press submit form button, I call onsubmit method
I have an array of javascript objects and I want to press a submit
If we type something in the text area and press submit button, the values
When a user press submit button I received 7 copies duplicate mail in my
Something is eluding me here. Every time I press the submit button, the form
I have a form with lots of fields and when I press the submit

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.