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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:06:27+00:00 2026-06-18T00:06:27+00:00

I have a simple MVC application that retrieves DB Server, database, username and password

  • 0

I have a simple MVC application that retrieves DB Server, database, username and password from the user to store in an XML file. I want to add a “Test Connection” button to the screen and have it execute a method on the controller called TestConnection. The problem is the TestConnection method resets all the information on the screen when clicked since the View is being returned with no model. (because a GET operation is occurring). Here is my code:

From the Controller (named FrameworkConfigurationController.cs)

  public ActionResult TestConnection()
    {
        return View("Index");
    }

    [HttpPost]
    public ActionResult TestConnection(FrameworkConfigurationViewModel viewModel)
    {           
        // TODO: Test will occur here
        viewModel.DbConnectionMessage = string.IsNullOrEmpty(viewModel.DatabaseName) ? "Connection unsuccessful" : "Connection successful";

        return View("Index", viewModel);
    }

From my View (FrameworkConfiguration/Index):

@model Framework.ViewModels.FrameworkConfigurationViewModel

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
 }

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)

<fieldset>
    <legend>FrameworkConfigurationViewModel</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.ServerName)
    </div>

    @* Edited for brevity *@

    <button type="submit" onclick="location.href='@Url.Action("TestConnection")'">
       Test Connection</button>

    @Html.ValueFor(model => model.DbConnectionMessage)

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

<div>
    @Html.ActionLink("Back to Dashboard", "Index", "Home")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Admittedly, I am new to MVC programming. I’m coming from a Silverlight/MVVM background so the concept is not foreign to me…the disconnected nature of web programming is. I’ve followed some tutorials out there, but none of them seem to cover this type of thing – every example is contrived. I know how to do this with webforms and code-behind, but I would like to accomplish this with MVC.

Is there some way to “force” the POST operation instead of GET? I was under the impression that

<button type="submit">

accomplished that. Perhaps the implementation of the onclick I have written isn’t correct. I am sure this is HTML 101 stuff, but I can’t seem to find a simple answer to this.

Thanks for any help you can offer,

Jason

  • 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-18T00:06:28+00:00Added an answer on June 18, 2026 at 12:06 am

    Why not have the Test Connection button trigger an Ajax action to call the controller, and display the result?

    That way you avoid submitting your entire page.

    In case you’re not familiar with the details, here’s a good overview on getting started with Ajax and MVC 4

    http://ofps.oreilly.com/titles/9781449320317/ch_AJAX.html

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

Sidebar

Related Questions

I have a simple Spring MVC application that looks up some user details from
I have a very simple ASP.Net MVC Application that I have produced from an
I have an ASP.NET MVC application that allows the user to upload a file
I have a simple MVC 4 (Beta) Application and just observed something that I
I have learned from the sencha doc how to create a simple MVC application,
I have written a simple ASP.NET MVC 2 application that stores data and can
I have ASP.NET MVC 4 application that contains library of some simple jQuery widgets.
I have created a simple MVC application that is using the .Net Membership Provider
I have successfully setup a simple mvc application that lists teams. I'm using Ninject
I have a simple application with MVC pages that have no javascript, images or

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.