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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:59:28+00:00 2026-05-23T14:59:28+00:00

A brief description of what I am doing. I am creating a rather crude

  • 0

A brief description of what I am doing. I am creating a rather crude IS Asset tracking database using ASP MVC 3 and EF Code First approach. I can create a new asset. I can view the details on an asset. I can even display the edit view and edit the AssetTag. However the record will not update any of the other fields. If I edit the LocationName for instance. It will act like it is posting and return me to the Index view, but the record never actually posts the change.

I have created the Model below

public class AssetModel
{
    public int id { get; set; }
    public string AssetTag { get; set; }
    public virtual Location Location { get; set; }
    public virtual Hardware Hardware { get; set; }
    public virtual Software Software { get; set; }
    public virtual User User { get; set; }
}



public class Location
{
    public int LocationId { get; set; }
    public string LocationName { get; set; }
}
public class Hardware
{
    public int HardwareId { get; set; }
    public string Manufacturer { get; set; }
    public string Make { get; set; }
    public string Model { get; set; }

}

public class Software
{
    public int SoftwareId { get; set; }
    public string PublisherName { get; set; }
    public string SoftwarePackageName { get; set; }
    public string SoftwarePackageVersion { get; set; }
    public string SerialNumber { get; set; }
    public bool IsVolumeLicense { get; set; } // as in "Yes this is a Vol. Lic. Agreement"
    public LicenseAgreement LicenseAgreement { get; set; }
}

public class LicenseAgreement 
{
    public int LicId { get; set; }
    public string VolumeLicenseAgreementCompany { get; set; }
    public string AgreementIdentifier { get; set; } 
    public DateTime VolumeLicenseStartDate { get; set; }
    public DateTime VolumeLicenseExpirationDate { get; set; }
    public Int16 NumberOfLicenses { get; set; }

}

public class User
{
    // may remove this at some time and pull from Active Directory.
    // for now we take the easy route.
    public int UserId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

I have this DbDataSet that uses the AssetModel above:

public class AssetContext : DbContext
{
    public DbSet<AssetModel> Assets { get; set; }
 }

In my AssetController I have this for Edit:

public ActionResult Edit(int id)
    {
        AssetModel assetmodel = db.Assets.Find(id);
        return View(assetmodel);
    }
    //
    // POST: /Asset/Edit/5

    [HttpPost]
    public ActionResult Edit(AssetModel assetmodel)
    {
        if (ModelState.IsValid)
        {
            db.Entry(assetmodel).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(assetmodel);
    }

And here is the Edit.cshtml

@model ISHelpDesk.Models.AssetModel

@{
     ViewBag.Title = "Edit";
  }

 <h2>Edit</h2>
@using (Html.BeginForm("Edit", "Asset")) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>AssetModel</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.AssetTag)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.AssetTag)
        @Html.ValidationMessageFor(model => model.AssetTag)
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.Location.LocationName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Location.LocationName)
        @Html.ValidationMessageFor(model => model.Location.LocationName)
    </div>

    </fieldset>
<p><input type="submit" value="Save"</p>
 }

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
  • 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-23T14:59:28+00:00Added an answer on May 23, 2026 at 2:59 pm

    your AssetContext should be

    public class AssetContext : DbContext
    {
        public DbSet<AssetModel> Assets { get; set; }
        public DbSet<Location> Locations { get; set; }
        public DbSet<Hardware> Hardwares { get; set; }
        public DbSet<Software> Softwares { get; set; }
        public DbSet<LicenseAgreement> LicenseAgreements { get; set; }
        public DbSet<User> Users { get; set; }
    }
    

    this is registering each of your classes as a table in the DbContext, what you had before showed your DbContext consists only of AssetModel

    Update: The issue may be that when you get to the post method of the edit, the Asset is no longer associated with the database Asset it was originally loaded from, have a go at changing it to

    public ActionResult Edit(int id)
    {
        AssetModel assetmodel = db.Assets.Find(id);
        return View(assetmodel);
    }
    
    [HttpPost]
    public ActionResult Edit(int id, FormCollection collection)
    {
        AssetModel assetmodel = db.Assets.Find(id);
    
        if (TryUpdateModel(assetmodel))
        {
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(assetmodel);
    }
    

    Obviously this may not be the behaviour you want I’m just trying to see if you can get some changes persisted and go from there

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

Sidebar

Related Questions

First, a brief description of the library that brought this up: I have a
Can someone please fill in the blanks for me, including a brief description of
I am looking for a brief description of the use of an assembler in
In my information area of my app I want to show a brief description
Firstly, let me give a brief description of the scenario. I'm writing a simple
I have product website. On one page I show thumbnails and a brief description
A brief description... I have 4 tables. contacts (a list of each person, unique
Brief Description of the app: I have written a Delphi application that allows a
Right now I have a loop in the view that displays a brief description
Would appreciate any kind of help here. A brief description about scenario - There

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.