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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:14:49+00:00 2026-05-18T02:14:49+00:00

I’m just starting to explore asp mvc and jquery. I have a simple form

  • 0

I’m just starting to explore asp mvc and jquery.

I have a simple form that has 2 fields, a Date and an Amount.

The behaviour I am trying to achieve is that when the form is submitted, if the record doesn’t already exist in my database then add the item. If it does already exist then warn and ask the user for confirmation. If the user proceeds then overwrite the existing record.

Here is my Mark Up

<% using (Html.BeginForm())
       { %>
    <div>
        <%:Html.LabelFor(mod => Model.bal.Date) %>
    </div>
    <div>
        <%: Html.TextBoxFor(mod => Model.bal.Date)%>
        <%:Html.ValidationMessageFor(mod => Model.bal.Date)%>
    </div>
    <div>
        <%: Html.LabelFor(mod => Model.bal.Amount)%>
    </div>
    <div>
        <%: Html.TextBoxFor(mod => Model.bal.Amount)%>
        <%: Html.ValidationMessageFor(mod => Model.bal.Amount)%>
    </div>
    <p>
        <input type="submit" value="Create" />

And here is my controller code

        [HttpPost]
        public ActionResult Index(Balance bal)
        {

            var dataContext = new DataDataContext();
            if (ModelState.IsValid)
            {
                // Check if exsists
                if (dataContext.Balances.ToList().Contains(bal, new BalanceEquality()))
                {
                    //Exsists, Warn then edit
                    // Add code here to open popup 
                    // if Continue then over write exsisting data in db

                }
                else
                {
                    //Not exsist, insert
                    dataContext.Balances.InsertOnSubmit(bal);
                    dataContext.SubmitChanges();
                }
            }

            compModel myModel = new compModel();
            myModel.bal = bal;
            myModel.allBalances = dataContext.Balances.OrderBy(ball => ball.Date).ToList();
            return View(myModel);
        }

The problem I have is how to display and get the results from a Jquery Popup from within my Controller.

I thought about setting a variable in the ViewData collection, but this didn’t seem like “best Practice” to me

Thanks

  • 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-18T02:14:50+00:00Added an answer on May 18, 2026 at 2:14 am

    You are at the wrong end of your execution sorry, the Controller is independent of the View i.e. you can’t reply to the response during execution of the Controller code other than to return a View. You could do one of at least four things (I am sure there are other solutions):

    1 – Use Ajax to make a call to a JsonResult controller method that determines whether the entry already exists after the submit button is clicked – then based no the result of the query you can display a popup whereby “Yes” submits the form and overwrites, or “No” stops the form being submitted.

    2 – You can return the view (without submitting the query to the db) and ask the user to confirm overwriting the existing record – but you would have to add some additional logic like a hidden input field in order to determine that the user has seen the message and has agreed to overwrite. This wouldn’t be a great approach and probably wouldn’t be very intuitive for the user.

    3 – Add an “overwrite existing record” checkbox to the form that confirms that the user want’s to overwrite the data if it already exists.

    4 – Logically seperate Add and Edit for the user so that when a user wants to update an existing record they select the record from a list and edit the existing data – this would be the most traditional method I would think. Then if the user attempts to add a new item that is the same as an existing one you simply re-display the page with an error stating that the record already exists.

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

Sidebar

Related Questions

Just starting out in asp.net. Have just created a login.aspx page in my site
Just starting with ASP.NET and find it difficult to use the GridView. I have
Just starting to explore the 'wonders' of regex. Being someone who learns from trial
I am just starting out with DI & unit testing and have hit a
I am just starting to learn javascript, so I don't have the skills to
I'm currently writing a website in ASP.NET MVC, and my database (which doesn't have
I'm just starting to explore C++, so forgive the newbiness of this question. I
I am just starting to explore/use the UML modeling support in Visual Studio 2010
Just starting out with jQuery and this problem seems to be impossible to me.
Just starting learning about ajax requests using jQuery. I've tried looking at other posts

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.