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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:20:31+00:00 2026-05-28T07:20:31+00:00

I have a View that handles the Edit action for editing a weekly update

  • 0

I have a View that handles the Edit action for editing a weekly update on your weight and nutrition. Editing a singular model is all good. I am using EditorFor to create the fields.

My problem is that I want to also display a read only version of last week’s results as a guide but I would like to use DisplayFor so that it formats bools to be disabled checkboxes and formats the dates based on my formatting in the model. I added the model to the Viewbag and tried to access it by using @Html.DisplayFor(x => x.BodyWeight, (myproject.Models.WeeklyReport)ViewBag.LastReport) however it just brings up the data in the model that I sent to the view and not the Viewbag data. What is the best method to display this kind of data while keeping the constraints/formatting of the model intact?

Thanks.

View

@model myproject.Models.WeeklyReport

<h2>Weekly Report - Week 1</h2>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <table class="weeklyreport">
        <tr>
            <th>Week</th>
            <td class="result-bold">Goals</td>
            <td>Current Week</td>
        </tr>
        <tr>
            <th>Body Weight</th>
            <td class="result-bold">@Html.DisplayFor(x => x.BodyWeight, (myproject.Models.WeeklyReport)ViewBag.Goals)</td>
            <td>@Html.EditorFor(model => model.BodyWeight)
                @Html.ValidationMessageFor(model => model.BodyWeight)</td>
        </tr>
        <tr>
            <th>Diary Reviewed</th>
            <td class="result-bold">@Html.DisplayFor(x => x.DiaryReviewed, (myproject.Models.WeeklyReport)ViewBag.Goals)</td>
            <td>@Html.EditorFor(model => model.DiaryReviewed)
                @Html.ValidationMessageFor(model => model.DiaryReviewed)</td>
        </tr>
    </table>

Controller

public ActionResult Edit(int id)
{
    WeeklyReport goal = new WeeklyReport()
    {  
        BodyWeight = 60,
        DiaryReviewed = true
    };

    WeeklyReport rpt = new WeeklyReport()
    {
        BodyWeight = 68,
        DiaryReviewed = false

    };
    ViewBag.LastReport = goal;
    return View(rpt);
}
  • 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-28T07:20:32+00:00Added an answer on May 28, 2026 at 7:20 am

    You can create a viewmodels or partialViews and pass the viewbag item to the partial.

    An example of viewmodel usage

     public class WeeklyReportViewModel
        {
          public WeeklyReport LastReport { get; set; }
          public WeeklyReport Report { get; set; }
        }
    

    combine the reports

    public ActionResult Edit(int id)
    {
      WeeklyReport goal = new WeeklyReport()
      {  
        BodyWeight = 60,
        DiaryReviewed = true
      };
    
      WeeklyReport rpt = new WeeklyReport()
      {
        BodyWeight = 68,
        DiaryReviewed = false
    
      };
    
      WeeklyReportViewModel viewmodel = new WeeklyReportViewModel()
      {
        LastReport = goal,
        ActualReport = rpt
      }
    
      return View(viewmodel);
    

    }

    In the view

    @model myproject.ViewModels.WeeklyReportViewModel 
    
    @Html.DisplayFor(x => x.LastReport.BodyWeight)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such view that handles user registration. After creating new user i want
I have an Action method in an ASP.NET MVC Controller class that handles form
When I have a controller, e.g. article I often have a action_view() that handles
I have a view that has a list of jobs in it, with data
I have a view that I want to add some custom drawing to. I
I have a View that can vary significantly, depending on the 'mode' a particular
I have a view that is joining two tables and ordering by the first
I have a view that is loaded in the MainWindow.xib. It is just a
I have a view that takes data from my site and then makes it
I have a view that I want to be converted into JSON. What is

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.