Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my index page

HTML
@model MvcApplication90.vikrant

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<html>
<head>
    <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
    <script type ="text/javascript">
        $("#submit").click(function () {

            var url = "/Home/Index";
            var name = $("#name").val()
            var address = $("#address").val()
            $.post(url, { Name: name, Address: address }, function (data) {
                $("#result").html(data)


            })
        })
</script>
    
</head>
<body>

<h2>Index</h2>
@section Feature
{
    @using (Html.BeginForm( "Home","Index", FormMethod.Post, new { id = "frm"}))
    {
        <table>
            <tr>
                <td> 
                @Html.LabelFor(model => model.name)
                @Html.TextBoxFor( Model => Model.name)
                
                </td>
            </tr>

            <tr>
                <td>
                    @Html.LabelFor( model => model.address)
                    @Html.TextBoxFor( model => model.address)
                </td>
            </tr>
           <tr>
               <td>
               <input type ="submit" id ="dd", value ="submit" />
                   </td>
           </tr>
        </table>
      <div id="result" style="color:gray;"></div>
    }

  
        </body>
</html>

layoutpage
HTML
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
    
    <script src="@Url.Content("~/Scripts/modernizr-2.5.3.js")" type="text/javascript"></script>
    
</head>

<body>
    @RenderBody()
    @RenderSection("Feature")

</body>
</html>


CONTROLER

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;



namespace MvcApplication90.Controllers
{
    public class HomeController : Controller
    {
        [HttpGet]
        [ActionName("Index")]
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        [ActionName("Index")]
        public ActionResult Index( FormCollection formcollection)
        {
            vikrant cc = new vikrant();
            cc.name = formcollection["name"];
            cc.address = formcollection["address"];
            hospitalEntities tt = new hospitalEntities();
            tt.addemp(cc);
            return "thank u" + Name + "SUBMITTED";
          


        }

    }
}

Kindly help me ITS URGENT
Posted
Updated 2-Feb-15 23:36pm
v2
Comments
CHill60 3-Feb-15 5:39am    
It's not urgent. We don't get paid for helping out here and we all have our own priorities. Using words like "urgent" usually has the exact opposite effect of getting things answered quickly. And don't use all capitals - it's shouting on the internet and rude - something else that will make people find something better to do than answer your question
Member 10874581 3-Feb-15 5:40am    
ok sir sorry for that but try to solve my problem
CHill60 3-Feb-15 5:41am    
This is not my area of expertise, but I have formatted your code to make it easier to read for someone who is more expert in this area
Member 10874581 3-Feb-15 5:43am    
ok thanks
Sinisa Hajnal 3-Feb-15 5:57am    
Things that look off in your code: you have submit button and the form with post action which by default submits to the controller. Your javascript click handlers is unnecessary. Secondly, in your click handler (in case it is invoked) calls Home/Index with parameters Name (not name) and Address (not address)...C# is case sensitive, although I admit I'm not sure in this situation if that has any effect. Can you say exactly which line causes the error? Can you check the values both in the controller (breakpoint) and in the javascript (breakpoint or console.log) ?

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