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

  • Home
  • SEARCH
  • 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 440411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:52:13+00:00 2026-05-12T20:52:13+00:00

Using the Authors/Books catalog example, let’s say I want to edit the info for

  • 0

Using the Authors/Books catalog example, let’s say I want to edit the info for the books of a specific author.

When someone navigates to domain.com/Books/Edit/2, I want to display an edit view for all the books where Author_ID = 2. Among the various book info is the book category (fiction, non-fiction, textbook, whatever) These categories are in their own table and are referenced by a Category_ID.

What’s the best way to set up the edit form?

Currently in my controller I have something like this:

public ActionResult Edit(int id)
        {

            IQueryable<Book> books =  bookRepository.FindBooksForAuthor(id);
            return View(books);
        }

And in my partial view:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IQueryable<Authors.Models.Book>>" %>

    <%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %>

    <% using (Html.BeginForm()) {%>

        <fieldset>
            <legend>Fields</legend>
            <%var i = 0;
              foreach (var book in Model)
              {%>



            <p>
                <label for="Category_ID">Category_ID:</label>
                <%= Html.TextBox("Category_ID", book.Category_ID)%>
                <%= Html.ValidationMessage("Category_ID", "*")%>
            </p>
            <p>
                <label for="Description">Description:</label>
                <%= Html.TextBox("Description", book.Description)%>
                <%= Html.ValidationMessage("Description", "*")%>
            </p>

            <%i++;
              } %>
               <p>
                <input type="submit" value="Save" />
            </p>
        </fieldset>

    <% } %>

Is my Inherits set properly at the top of the view since I’m passing an IQueryable object?

More importantly, how do I get the Category_ID field to be a DropDown with the correct category selected?
Can I just send the data for the dropdown to the view and figure out the selected item at the view level?

ViewData["categories"] = new SelectList(_db.BookCategories.ToList().OrderBy(b => b.Category_Title), "Category_ID", "Category_Title");
  • 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-12T20:52:13+00:00Added an answer on May 12, 2026 at 8:52 pm

    You could create view model class containing list of books and select list of categories:

    public class BooksEditViewModel 
    {
        public IQueryable<Authors.Models.Book> Books { get; set; }
        public IQueryable<BookCategory> BookCategories { get; set; }
    }
    

    Then use BooksEditViewModel as view model

    System.Web.Mvc.ViewUserControl<BooksEditViewModel>
    

    and code dropdown with

    Html.DropDownList("Category_ID", new SelectList(Model.BookCategories,"Category_ID", "Category_Title",book.Category_ID);
    

    You should also read about list binding:

    http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx

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

Sidebar

Related Questions

Fresh from the Djangobook tutorial using the Books app example, you have Book related
Am building a Book search API using Lucene. I need to index Book Name,Author,
I recently read a nice post on using StringIO in Ruby. What the author
If my models.py has a ManyToMany relationship between books and authors, and if for
When I read books about WPF, I saw the authors mention XPS like it
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have

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.