Json 在MVC操作中两次命中断点

Json 在MVC操作中两次命中断点,json,asp.net-mvc-3,razor,Json,Asp.net Mvc 3,Razor,我在razor中从事mvc项目。在这个项目中,我从事导入和导出模块的工作。 现在在我的操作中,我返回了JSON对象。现在在Http Get请求或Http Post请求中,我都遇到了相同的问题。因为断点命中了两次,所以我的记录在数据库中添加了两次 下面是我的剧本 <script type="text/javascript"> $(document).ready(function (e) { $(".update").live('click', function

我在razor中从事mvc项目。在这个项目中,我从事导入和导出模块的工作。 现在在我的操作中,我返回了JSON对象。现在在Http Get请求或Http Post请求中,我都遇到了相同的问题。因为断点命中了两次,所以我的记录在数据库中添加了两次

下面是我的剧本

<script type="text/javascript">
    $(document).ready(function (e) {
        $(".update").live('click', function () {
            var id = $(this).attr('id');
            var str = "";
            $(this).parent('td').parent('tr').find('td.data').each(function () {
                str = str + ";" + $(this).text().trim();
            });
            if (str.length > 0) {
                str = str.substring(1, str.length);
            }
            var header = $("#hdn_header").val();
            $.post('/ImportCSV/Update', {
                ImportData: str,
                ImportHeader: header
            }, function (result) {
                var CompName = result.CompanyName;
                var CompPhone = result.CompanyPhone;
                var CompEmail = result.CompanyEmail;
                var CompWebsite = result.CompanyWebsite;
                var CompAddress = result.CompanyAddress;
                var CompZip = result.CompanyZip;
                var CompCity = result.CompanyCity;
                var CompCountry = result.CompanyCountry;
                var CompNote = result.CompanyNote;
                var ConFirstName = result.ConFirstName;
                var ConLastName = result.ConLastName;
                var ConTitle = result.ConTitle;
                var ConPhone = result.ConPhone;
                var ConEmail = result.ConEmail;
                var ConNote = result.ConNote;
                var ConMobile = result.ConMobile;
                $(".update").each(function () {
                    if ($(this).attr('id') == id) {
                        var i = parseInt('1');
                        $(this).parent('td').parent('tr').find('td.data').each(function () {
                            if ($(this).text().trim() != CompName && $(this).index() == 2) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != CompPhone && $(this).index() == 3) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != CompEmail && $(this).index() == 4) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != CompWebsite && $(this).index() == 5) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != CompAddress && $(this).index() == 6) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != CompZip && $(this).index() == 7) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != CompCity && $(this).index() == 8) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != CompCountry && $(this).index() == 9) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != CompNote && $(this).index() == 10) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != ConFirstName && $(this).index() == 12) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != ConLastName && $(this).index() == 13) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != ConTitle && $(this).index() == 14) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != ConPhone && $(this).index() == 15) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != ConMobile && $(this).index() == 16) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != ConEmail && $(this).index() == 17) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                            if ($(this).text().trim() != ConNote && $(this).index() == 18) {
                                {
                                    $(this).css('backgroundColor', '#FFFFC0');
                                    return;
                                }
                            }
                        });
                    }
                });
            });
            return false;
        });
    });
</script>

$(文档).ready(函数(e){
$(“.update”).live('单击',函数(){
var id=$(this.attr('id');
var str=“”;
$(this).parent('td').parent('tr').find('td.data').each(函数)(){
str=str+“;”+$(this.text().trim();
});
如果(str.length>0){
str=str.substring(1,str.length);
}
var header=$(“#hdn_header”).val();
$.post(“/importsv/Update”{
进口资料:str,
导入顺序:标题
},函数(结果){
var CompName=result.CompanyName;
var CompPhone=result.CompanyPhone;
var CompEmail=result.CompanyEmail;
var CompWebsite=result.CompanyWebsite;
var CompAddress=result.CompanyAddress;
var CompZip=result.CompanyZip;
var CompCity=结果公司性;
var CompCountry=结果公司国家;
var CompNote=result.CompanyNote;
var ConFirstName=result.ConFirstName;
var ConLastName=result.ConLastName;
var ConTitle=result.ConTitle;
var ConPhone=result.ConPhone;
var ConEmail=result.ConEmail;
var ConNote=结果。ConNote;
var ConMobile=result.ConMobile;
$(“.update”)。每个(函数(){
if($(this.attr('id')==id){
变量i=parseInt('1');
$(this).parent('td').parent('tr').find('td.data').each(函数)(){
if($(this.text().trim()!=CompName&$(this.index()==2){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
if($(this.text().trim()!=CompPhone&$(this.index()==3){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
if($(this.text().trim()!=CompEmail&$(this.index()==4){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
如果($(this.text().trim()!=CompWebsite&$(this.index()==5){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
if($(this.text().trim()!=CompAddress&&$(this.index()==6){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
if($(this.text().trim()!=CompZip&&$(this.index()==7){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
如果($(this.text().trim()!=CompCity&&$(this.index()==8){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
如果($(this.text().trim()!=CompCountry&&$(this.index()==9){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
如果($(this.text().trim()!=CompNote&$(this.index()==10){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
if($(this.text().trim()!=ConFirstName&$(this.index()==12){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
if($(this.text().trim()!=ConLastName&$(this.index()==13){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
if($(this.text().trim()!=ConTitle&$(this.index()==14){
{
$(this.css('backgroundColor','#FFFFC0');
返回;
}
}
if($(this.text().trim()!=ConPhone&$(this.index()==15){
{
$(此).cs
$(function() {
    $('#someForm').submit(function() {
        $.post('/ImportCSV/Update', { ImportData: str, ImportHeader: header }, function (result) {
            var CompName = result.CompanyName;
        });

        return false; // <-- that's the important part
    });
});