Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My url is http://localhost:54684/MyTest/Register

My controller Name is MyTest
My view(ActionMethod name)is Register

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Configuration;
using MySql.Data.MySqlClient;
using ModelFields;

namespace WebApplicationPractise.Controllers
{
    public class MyTestController : Controller
    {
        // GET: MyTest
        public ActionResult Home()
        {
            
            return View();
        }

        [HttpPost]
        public ActionResult Register(RegisterFields rf)
        {
            string connection = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
            using(MySqlConnection mysqlcon =new MySqlConnection())
            {
                string query = "insert into 3tier.jagadeesh(FirstName,LastName,Age,Address) values(@FirstName,@LastName,@Age,@Address)";
                using(MySqlCommand cmd =new MySqlCommand(query))
                {
                    cmd.Connection = mysqlcon;
                    mysqlcon.Open();
                    cmd.Parameters.AddWithValue("@FirstName", rf.FirstName);
                    cmd.Parameters.AddWithValue("@LastName", rf.LastName);
                    cmd.Parameters.AddWithValue("@Age", rf.Age);
                    cmd.Parameters.AddWithValue("@Address", rf.Address);
                    mysqlcon.Close();
                    
                }
            }
           
            
            return View(rf);
        }

    }
}

Above one is my controller and below one is my view
@model ModelFields.RegisterFields
@{
    ViewBag.Title = "Register";
    Layout = "~/Views/Shared/MyTestLayoutPage.cshtml";
}

@using (Html.BeginForm("Register", "MyTest", FormMethod.Post))
{
    @Html.TextBoxFor(model => model.FirstName, new { placeholder = "FirstName" });
    @Html.TextBoxFor(model => model.LastName, new { placeholder = "FirstName" });
    @Html.TextBoxFor(model => model.Age, new { placeholder = "FirstName" });
    @Html.TextBoxFor(model => model.Address, new { placeholder = "FirstName" });
    <input type="submit" value="submit" />
}

@if (Model != null)
{
    <script type="text/javascript">
        $(function () {
            alert("data inserted successfully");
        });
    </script>
}
Posted
Updated 24-Jan-19 8:50am
v3
Comments
F-ES Sitecore 24-Jan-19 11:59am    
Error messages tend to contain information that tells you what the problem is, so look at any error messages and go from there.
Member 14128794 24-Jan-19 12:12pm    
There is no errors in error list,actually i found my self problem with post method so i tired to execute with out post method again i got the error like this
No connection could be made because the target machine actively refused it 192.168.43.182:3306
F-ES Sitecore 24-Jan-19 12:40pm    
The server details in that error message don't match the url you are trying to test, the IP and port both differ. You're probably connecting to the wrong server. If this is something that used to work on your local machine but doesn't work on a deployed server then your code is probably using incorrect hard-coded urls. There isn't really enough info in your post for us to know why your url isn't working, all we can say is you're connecting to the wrong machine, or the target machine doesn't have a web server running on port 3306.
Richard MacCutchan 24-Jan-19 12:43pm    
Showing your code here is irrelevant. What you need to do is check that your website is correctly configured and listening on port 54684. According to the error message you are trying to connect to port number 3306.

I have seen a similar issue before in QA; do you have more than one user account that you are posting to?
Bryian Tan 24-Jan-19 14:43pm    
very likely the MySQL server not running or the firewall blocked the port 3306

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900