Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Asp.Net Core Mvc JsonResult Not Triggered

$
0
0

publicclassQuote
    {         
        publicstringFullName{get;set;}

        publicstringEmail{get;set;}

        publicstringPhone{get;set;}

        publicstringBudget{get;set;}      

        publicstringMessage{get;set;}
    }

$("#submit").on('click',function(){$.ajax({ url:'/Home/QuoteMessageSend', type:"POST", dataType:'json', data:$("#QuoteForm").serialize(), error:function(xhr, textStatus, error){ console.log(xhr.statusText); console.log(textStatus); console.log(error);}});});

<form id="QuoteForm">
                <p>
                    <input id="fullName" asp-for="FullName" placeholder="Full Name"class="contact-item"/>
                    <span id="fnoutput"></span>
                </p>
                <p>
                    <input id="email" asp-for="Email" placeholder="Email" class="contact-s-item" />
                    <span id="emoutput"></span>
                </p>
                <p>
                    <input id="phone" asp-for="Phone" placeholder="Phone" class="contact-s-item" />
                    <span id="phoneoutput"></span>
                </p>
                <p>
                    <select asp-for="Budget" class="contact-l-item">
                        <option value="" disabled selected>Budget</option>
                        <option value="200-1000">€200-800</option>
                        <option value="800-4000">€800 - €4000</option>
                        <option value="4000-12000">€4000-12000</option>
                        <option value="12000+">€12000+</option>
                    </select>
                    <span id="budgetoutput"></span>
                </p>
                <p>
                    <textarea id="message" asp-for="Message" placeholder="Your Ideas" class="contact-m-item"></textarea>
                    <span id="messageoutput"></span>
                </p>
                <button id="submit" type="button">Submit Now</button>
            </form>

          

[HttpPost]
        publicJsonResultQuoteMessageSend(Quote quote)
        {
            QformCheck(quote);
            if(qfncheck && qemcheck&& qphonecheck && qbdcheck&& qmsgcheck)
            {
                using(MySqlConnection connection=newMySqlConnection("Server=localhost; Database=dbname; Uid=root; Pwd=123456; SSL Mode=none;"))
                {
                    using(MySqlCommand cmd=newMySqlCommand("INSERT INTO quotes(FullName, Email, Phone, Budget, Message) VALUES(@fn, @em, @ph, @bdg, @msg)", connection))
                    {
                        connection.Open();
                        cmd.Parameters.AddWithValue("@fn", quote.FullName);
                        cmd.Parameters.AddWithValue("@em", quote.Email);
                        cmd.Parameters.AddWithValue("@ph", quote.Phone);
                        cmd.Parameters.AddWithValue("@bdg", quote.Budget);
                        cmd.Parameters.AddWithValue("@msg", quote.Message);
                        cmd.ExecuteNonQueryAsync();
                        connection.Close();
                    }
                }
                returnJson(new{ data = quote, success=true, responseText=""});
            }
            else
            {
                returnJson(new{ data = quote, success=true, responseText=""});
            }                

        }

While this code works flawlessly in local, it doesn't work when I broadcast. When I check the item and look at it, all the necessary code I can see it being called. I thought the problem might be in the database connection, I created a simple sample table and pulled data on the server works smoothly. However, when I register to the database with JsonResult, it does not get into the database almost on the server side. It does not give any errors. Just looking at the item with check item again, I could see that it wrote 404 bad request. Apart from that I have there is nothing.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>