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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:26:41+00:00 2026-05-12T08:26:41+00:00

Greetings. In attempt to wrap my head around MVC I’ve just implemented a simple

  • 0

Greetings.

In attempt to wrap my head around MVC I’ve just implemented a simple add/delete page which views records as well. This makes it easier for users to do most things from one page instead of having to navigate away to do simple tasks. The page lets you add a record (a business which has an ID and a name) which works fine. However when I delete a record I’ve done the following to allow deletions to occur:

<%= Html.ActionLink("delete", "DeleteBusiness", new { businessToDelete = B.BusinessID }) %>

This works fine to delete the record. This is what my controller action looks like for it:

public ActionResult DeleteBusiness(string businessToDelete)
{
     try
     {
       if (!ModelState.IsValid)
         return View("Businesses", _contractsControlRepository.ListBusinesses());

         _contractsControlRepository.DeleteBusiness(businessToDelete);

         return View("Businesses", _contractsControlRepository.ListBusinesses());
     }
     catch
     {
       return View("Businesses", _contractsControlRepository.ListBusinesses());
     }
}

So from the Businesses page I have an ActionLink which just directs me to this action in the controller which does the work and then returns the view that I was previously at. Then problem is that once I’ve deleted the record my actual URL ends up like this:

http://localhost:3340/Accounts/ContractsControl/DeleteBusiness?businessToDelete=TEST

This isn’t good, because when I then go to add a new record, it won’t let me. My controller action which lets me add records looks like this:

  [AcceptVerbs(HttpVerbs.Post)]
  public ActionResult Businesses(Business business)
  {
    try
    {
      if (!ModelState.IsValid)
        return View(_contractsControlRepository.ListBusinesses());

      _contractsControlRepository.CreateBusiness(business);
      return View(_contractsControlRepository.ListBusinesses());
    }
    catch
    {
      return View(_contractsControlRepository.ListBusinesses());
    }
  }

Any post request is seen as creating new records. Is this correct? Here’s my view just to top it all off:

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

  <fieldset class="inline-fieldset">
    <legend>Add Business</legend>

    <p>
    <label for="ID">ID</label>

    <%= Html.TextBox("BusinessID", null, new { style = "width:50px;", @class = "uppercase", maxlength = "4" })%>
    <%= Html.ValidationMessage("BusinessID", "*")%>

    <label for="Business">Business</label>

    <%= Html.TextBox("BusinessCol")%>
    <%= Html.ValidationMessage("BusinessCol", "*")%>

    <input type="submit" value="Add" />
  </p>

  <%= Html.ValidationSummary("Uh-oh!") %>

  </fieldset>

<% } %>

<table>
<tr>
<th>ID</th>
<th>Business</th>
<th></th>
<th></th>
</tr>
  <% foreach (Business B in ViewData.Model)
  { %>
    <tr>
      <td><%= B.BusinessID %></td>
      <td><%= B.BusinessCol %></td>
      <td class="edit"><%= Html.ActionLink("edit", "EditBusiness", new { id = B.BusinessID }) %></td>
      <td class="delete"><%= Html.ActionLink("delete", "DeleteBusiness", new { businessToDelete = B.BusinessID }) %></td>
    </tr>
  <% } %>
</table>

As you can see at the very bottom I have the action links (ignore the edit one). So if I delete a record, then immediately try to add one, it won’t work because (I’m assuming) of the URL being wrong. What am I doing wrong here?

FIXED

  public RedirectToRouteResult DeleteBusiness(string businessToDelete)
  {
    try
    {
      if (!ModelState.IsValid)
        return RedirectToAction("Businesses");

      _contractsControlRepository.DeleteBusiness(businessToDelete);

      return RedirectToAction("Businesses");
    }
    catch
    {
      return RedirectToAction("Businesses");
    }
  }
  • 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-12T08:26:41+00:00Added an answer on May 12, 2026 at 8:26 am

    Why don’t you redirect user back do List Businesses page if delete succeded?

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

Sidebar

Related Questions

Greetings! I'm working on wrapping my head around LINQ. If I had some XML
Greetings, SO. I have some code which I've made attempts at compiling using gcc,
Greetings Friends, I am trying to overlay the simple 2D game I am developing
Greetings I've been working on a homework in which I must create a linked
Greetings, I'm having the following issue: When I attempt to execute several INSERT INTO
Greetings. I have an RDLC file and am wanting to add a data source
Greetings. I have a function which watches the content of price field and updates
Greetings! I am developing Asp.net application, in which i need to use sqlite as
Greetings. I have an 2-D array of size [N][N] which will represent a rectangular
Greetings, I am trying to implement a TimeField model which only consists of HH:MM

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.