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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:09:27+00:00 2026-06-02T07:09:27+00:00

I have my values in LabelFors but when I do a postback the model

  • 0

I have my values in LabelFors but when I do a postback the model has default values.

@using (Html.BeginForm("Delete", "Event", FormMethod.Post))
{
    <p>
        @Html.LabelFor(m => m.EventID, "Event ID")<br />
        @Html.LabelFor(m => m.EventID, Model.EventID.ToString())
    </p>
    <p>
        @Html.LabelFor(m => m.DayCode, "Type of Event")<br />
        @Html.LabelFor(m => m.DayCode, Model.DayCode.ToString())
    </p>
    <p>
        @Html.LabelFor(m => m.EventDate, "Date of Event")<br />
        @Html.LabelFor(m => m.EventDate, Model.EventDate.ToShortDateString())
    </p>
    <p>
        @Html.LabelFor(m => m.Subject, "Person or Interest")<br />
        @Html.LabelFor(m => m.Subject, Model.Subject)
    </p>
    <p>
        @Html.LabelFor(m => m.EventDesc, "Description")<br />
        @Html.LabelFor(m => m.EventDesc, Model.EventDesc)
    </p>

    <table>
        <tr>
            <td>
                @Html.ActionLink("Back", "Index", new { month = Model.EventDate.Month,
                                                        year = Model.EventDate.Year,
                                                        day = Model.EventDate.Day})
            </td>
            <td>            
                <input id="delete" type="submit" value="Submit Changes" />
            </td>
        </tr>
    </table>
}

        public ActionResult Delete(int eventID, int year, int month, int day)
        {
            //Find Event then return to Index
            EventModel thisEvent = EventRepository.getDayEvent(eventID, year, month, day);
            return View(thisEvent);
        }



        [HttpPost]
        public ActionResult Delete(EventModel deletedEvent) //here Model only has 0, "", and 1/1/0001
        {
            EventRepository.DeleteEvent(deletedEvent);
            return RedirectToAction("Index", new { year = deletedEvent.EventDate.Year, month = deletedEvent.EventDate.Month, day = deletedEvent.EventDate.Day });
        }
  • 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-02T07:09:29+00:00Added an answer on June 2, 2026 at 7:09 am

    Your model is empty because your form contains no data. Labels aren’t considered to be data. They are labels for data. What you need is this:

    @Html.LabelFor(m => m.Subject, "Person or Interest")<br /> 
    @Html.DisplayFor(m => m.Subject)
    

    Edit: To make that above part clearer, I should stress that glosrob is right in that you only need the EventId in order to process the delete. Everything else is just for displaying the correct information so the user can verify they are deleting the correct record. I just wanted to make the point that labels aren’t considered to be form data, they are a visual indication.

    There’s a few things to note here though:

    Firstly, your EventId shouldn’t be open to modification, so it should be rendered with @Html.HiddenFor(m => m.EventId). This will render it as a hidden field which the user will be unable to see. That doesn’t mean it can’t be modified and you should eventually use an AntiForgeryToken to help against that.

    Secondly, you don’t need to specify the strings for the labels. You can do that on your viewmodel instead with data annotations:

    // DisplayName is in System.ComponentModel and not System.ComponentModel.DataAnnotations;
    using System.ComponentModel;  
    
    public class EventViewModel
    {
        [DisplayName("Person or Interest")]
        public string Subject { get; set; }
    }
    

    Then in the view you can just use @Html.LabelFor(m => m.Subject).

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

Sidebar

Related Questions

I have a model that I am using to present an index of a
I have a register form created by mvc3 scaffolding. e.g. <div class=editor-label> @Html.LabelFor(model =>
I have gotten this semi autogenerated code, but I am uncertain where the Post
i have the following view:- <div id = partialWrapper> @using (Ajax.BeginForm(Create, Answer, new AjaxOptions
So I have a view model call ProductViewModel which has a list of sites
I have the following view: @model ViewModels.Shared.BaseViewModel <div class=rep_tb0> <div class=rep_tr0> <div class=rep_td0>@Html.LabelFor(model =>
I've already seen this post: Changing the size of Html.TextBox But I cannot change
I have a simple field form <div class=field fade-label> @Html.LabelFor(model => model.Register.UserName) @Html.TextBoxFor(model =>
I have a Model that I can bind correctly for display purposes but I
I have values that are 64-bit unsigned ints, and I need to store them

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.