我的“Create.aspx”中有“Microsoft JScript 运行时错误:预期对象”错误,以下是我的代码,我已经导入了 jscript 文件。我的项目或软件的 jscript 版本是否不同?
注意:-使用的软件:Microsoft Visual Studio 2010 -项目:ASP.NET MVC 4 Internet Application(ASPX C#) -错误行:粗体句和 *
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcPOS.Models.Sales>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2 class="h2"> <%: (string)ViewBag.Title%> </h2>
<script type = "text/javascript" src="~/Scripts/jquery-1.7.1.min.js" >
**function DeleteRow() {
// Here I have used DataTables.TableTools plugin for getting selected row items
var oTT = TableTools.fnGetInstance('tbl'); // Get Table instance
var sRow = oTT.fnGetSelected(); // Get Selected Item From Table
// Set deleted row item to editable text boxes
$('#ItemSalesID').val($.trim(sRow[0].cells[0].innerHTML.toString()));
$('#ItemID').val($.trim(sRow[0].cells[1].innerHTML.toString()));
$('#Unit').val($.trim(sRow[0].cells[2].innerHTML.toString()));
$('#Price').val($.trim(sRow[0].cells[3].innerHTML.toString()));
$('#Total').val($.trim(sRow[0].cells[4].innerHTML.toString()));
$('.tbl').dataTable().fnDeleteRow(sRow[0]);
} //End DeleteRow()
$(document).ready(function () {
// here i have used datatables.js (jQuery Data Table)
$('.tbl').dataTable({
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"aButtons": [],
"sRowSelect": "single"
},
"bLengthChange": false,
"bFilter": false,
"bSort": false,
"bInfo": false
});
$('#SalesDateTime').datepicker();
var oTable = $('.tbl').dataTable();
}); //End Ready Function()
function Add() {
// Adding item to table
$('.tbl').dataTable().fnAddData([$('#ItemSalesID').val(), $('#ItemID').val(), $('#Unit').val(), $('#Price').val(), $('#Total').val()]);
// Making Editable text empty
$('#ItemSalesID').val("")
$('#ItemID').val("")
$('#Price').val("")
$('#Unit').val("")
$('#Total').val("")
} //End Add()
function Sales_save() {
// Step 1: Read View Data and Create JSON Object
// Creating SalesItem Json Object
var salesitem = { "SalesID": "", "ItemSalesID": "", "ItemID": "", "Unit": "", "Price": "", "Total": "" };
// Creating Sales Json Object
var sales = { "SalesID": "", "SalesNo": "", "SalesDateTime": "", "SalesTotal": "", "SalesPaid": "", "SalesChange": "", "SalesItem": [] };
// Set Sales Value
sales.SalesID = $("#SalesID").val();
sales.SalesNo = $("#SalesNo").val();
sales.SalesDateTime = $("#SalesDateTime").val();
sales.SalesTotal = $("#SalesTotal").val();
sales.SalesPaid = $("#SalesPaid").val();
sales.SalesChange = $("#SalesChange").val();
// Getting Table Data from where we will fetch Sales Item Record
var oTable = $('.tbl').dataTable().fnGetData();
for (var i = 0; i < oTable.length; i++) {
// IF This view is for edit then it will read SalesID from Hidden field
if ($('h2').text() == "Edit") {
salesitem.SalesID = $('#SalesID').val();
}
else {
salesitem.SalesID = 0;
}
// Set SalesItem individual Value
salesitem.ItemSalesID = oTable[i][0];
salesitem.ItemID = oTable[i][1];
salesitem.Unit = oTable[i][2];
salesitem.Price = oTable[i][3];
salesitem.Total = oTable[i][4];
// adding to Sales.SalesItem List Item
sales.SalesItem.push(salesitem);
salesitem = { "ItemSalesID": "", "ItemID": "", "Unit": "", "Price": "", "Total": "" };
}
// Step 1: Ends Here
// Set 2: Ajax Post
// Here i have used ajax post for saving/updating information
$.ajax({
url: "http://localhost:1221/Sales/Create",
data: JSON.stringify(sales),
type: "POST",
contentType: "application/json;",
dataType: "json",
success: function (result) {
if (result.Success == "1") {
window.location.href = "/Sales/Index";
}
else {
alert(result.ex);
}
}
}
);
}**
</script>
<% using (Html.BeginForm()) { %>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Sales</legend>
<%if (Model != null)
{%>
<input type="text" id = "SalesID" name ="SalesID" value = "<%: @Model.SalesID %>" readonly="readonly" />
<%}%>
<div class="editor-label">
<%: Html.LabelFor(model => model.SalesNo) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.SalesNo) %>
<%: Html.ValidationMessageFor(model => model.SalesNo) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.SalesDateTime) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.SalesDateTime) %>
<%: Html.ValidationMessageFor(model => model.SalesDateTime) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.SalesTotal) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.SalesTotal) %>
<%: Html.ValidationMessageFor(model => model.SalesTotal) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.SalesPaid) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.SalesPaid) %>
<%: Html.ValidationMessageFor(model => model.SalesPaid) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.SalesChange) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.SalesChange) %>
<%: Html.ValidationMessageFor(model => model.SalesChange) %>
</div>
<div>
<fieldset>
<legend>Add Item</legend>
<label>Item Sales ID :</label>
<%: Html.TextBox("ItemSalesID") %>
<label>Item ID :</label>
<%: Html.TextBox("ItemID") %>
<label>Price :</label>
<%: Html.TextBox("Price") %>
<label>Unit :</label>
<%: Html.TextBox("Unit") %>
<label>Total :</label>
<%: Html.TextBox("Total") %>
**<input type="button" value= "Add Row" onclick="Add()" />**
<br />
<br />
<table class="tbl" id="tbl">
<thead>
<tr>
<th>Item Sales ID</th>
<th>Item ID</th>
<th>Unit</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<%if (Model != null)
{%>
<% foreach (var item in Model.SalesItem)
{ %>
<tr>
<td>
<%: Html.DisplayTextFor(i => item.ItemSalesID) %>
</td>
<td>
<%: Html.DisplayTextFor(i => item.ItemID) %>
</td>
<td>
<%: Html.DisplayTextFor(i => item.Unit) %>
</td>
<td>
<%: Html.DisplayTextFor(i => item.Price) %>
</td>
<td>
<%: Html.DisplayTextFor(i => item.Total) %>
</td>
</tr>
<% } %>
<%}%>
<%else
{%>
<%}%>
</tbody>
</table>
<br />
**<input type="button" value="Delete Selected Row" onclick="DeleteRow()" />**
</fieldset>
</div>
<p>
**<input type="button" value="Sales Save" onclick="Sales_save()" />**
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">
<%: Scripts.Render("~/bundles/jqueryval") %>
<script src="<%: Url.Content("~/Scripts/jquery-1.7.1.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery-ui-1.8.20.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/json2.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/DataTables-1.8.1/media/js/jquery.dataTables.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/DataTables-1.8.1/extras/TableTools/media/js/TableTools.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/DataTables-1.8.1/extras/TableTools/media/js/ZeroClipboard.js") %>"type="text/javascript"></script>
<link href="<%: Url.Content("~/Content/themes/base/jquery.ui.all.css") %>" rel="stylesheet" type="text/css" />
<link href="<%: Url.Content("~/Content/DataTables-1.8.1/extras/TableTools/media/css/TableTools.css") %>" rel="stylesheet" type="text/css" />
<link href="<%: Url.Content("~/Content/DataTables-1.8.1/extras/TableTools/media/css/TableTools_JUI.css") %>" rel="stylesheet" type="text/css" />
</asp:Content>