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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:46:10+00:00 2026-06-02T02:46:10+00:00

I have mvc3 application here my problem is on same page i.e on Index.cshtml

  • 0

I have mvc3 application here my problem is on same page i.e on Index.cshtml
i have two partial view controlpartial.cshtml and webgridpartial.cshtml

now when i’m inserting data into database it works fine and page gets redirect to Index.cshtml and URL also gets clear.

But at the time of edit when i clicked on edit button and update all values and submit that values it is updated perfectly in database but page is not able to redirect again to Index.cshtml nor my URL gets cleared 🙁

Because of that I’m not able to edit any values once i done edit need to manually reset Index URL.

Any guesses?

Index.cshtml

@model Mapping.Models.SecurityIdentifierMappingViewModel

@{
    ViewBag.Title = "Index";
}

Index

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>


@*Partial control for all controls*@

<div id="main">
<div style="float:left;width:30%">
@Html.Partial("_ControlsPartial",Model)
</div>


<div style="margin-left:600px;margin-top:-20px">
@Html.Partial("_WebGridPartial",Model.MappingWebGridList)
</div>

</div>

HomeController.cs

  mydataEntities dbContext = new mydataEntities();
    DataRepository objRepository = new DataRepository();
//GET

public ActionResult Index(string userAction="Create",int id = 0 )
{
    var mappingobj = new SecurityIdentifierMappingViewModel();
    mappingobj.MappingWebGridList = dbContext.SecurityIdentifierMappings.ToList();

    if (id!=null && id > 0)
    {

        mappingobj.MappingControls = dbContext.SecurityIdentifierMappings.Find(id);
        if (userAction == "Delete")
        {
            dbContext.SecurityIdentifierMappings.Remove(mappingobj.MappingControls);
            dbContext.SaveChanges();
        }
    }
    else
    {
        mappingobj.MappingControls = new SecurityIdentifierMapping();
        mappingobj.MappingControls.PricingSecurityID = 0;
        mappingobj.MappingControls.CUSIP = "";
    }
    mappingobj.PricingSecurities = objRepository.GetPricingSecurityID();
    mappingobj.CUSIPs = objRepository.GetCUSIP();

    return View(mappingobj);
}


//POST

[HttpPost]
public ActionResult Index(SecurityIdentifierMappingViewModel objModel)
{
      //edit code
     if (objModel.MappingControls.Id > 0)
        {
            if (ModelState.IsValid)
            {
                dbContext.Entry(objModel.MappingControls).State = EntityState.Modified;
                try
                {
                    dbContext.SaveChanges();
                    return RedirectToAction("Index");
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw;
                }
            }

        }

        //insert code
        else
        {
            if (ModelState.IsValid)
            {
                dbContext.SecurityIdentifierMappings.Add(objModel.MappingControls);
                try
                {
                    dbContext.SaveChanges();
                    return RedirectToAction("Index");
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw;
                }
            }

        }

        objModel.MappingWebGridList = dbContext.SecurityIdentifierMappings.ToList();
        objModel.PricingSecurities = objRepository.GetPricingSecurityID();
        objModel.CUSIPs = objRepository.GetCUSIP();
        objModel.MappingControls = new SecurityIdentifierMapping();

        return View(objModel);

}

  • 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-02T02:46:11+00:00Added an answer on June 2, 2026 at 2:46 am

    Recommend instead of

    return View(objModel);
    

    to do

    return RedirectToAction("Index", new {Id = null});
    

    This is called Post-Redirect-Get model (PRG).

    If you wish to keep objModel. Place it in TempData and on Index(Get), to check TempData if the object is there. To use that instead of loading a new one.

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

Sidebar

Related Questions

In an MVC3 application I have a view rendering two Ajax partial views: a
here's my question: I have an MVC3 C# application and I need to update
I have been working on mvc3 application and trying to localize the same. I
My Problem: I have an MVC3 application where all views use a common master
I have a asp.net MVC3 Application with two users Admin and General.Cookies is saved
I have a problem with the user Login and Logout in an MVC3 application.
I have a MVC3 application with some XML files on the App_Data folder. To
I have a ASP.NET MVC3 application that handles time-consuming processes (copying a large file
i have created an mvc3 web application that uses forms based authentication. one part
In my MVC3 application, I have a queries class specific to each controller that

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.