日期:2014-05-16  浏览次数:20716 次

Jquery与.net MVC结合,通过Ajax

在工作中做了这么一个东西。

Html端:

@using Test.fh.Project.Storefront.ViewModels
@using Test.fh.Project.Storefront.Services
@model ProductViewModel
<div id="column-left">
    <div class="box">
        <div class="box-heading">
            Categories</div>
        <div class="box-content">
            <div class="box-category">
                
            </div>
        </div>
    </div>
</div>
<div id="content">
    <div class="breadcrumb">
        @Html.Partial("_Breadcrumbs")
    </div>
    <h1>
        @MvcHtmlString.Create(@Model.product_name)
    </h1>
    @using (Html.BeginForm("index", "Product"))
    {
        @Html.ValidationSummary(excludePropertyErrors: true)
        <div class="product-info">
            <div class="left">
                <div class="image">
                    <a href="@Url.Content("~/Content/images/" + @Model.thumbImagePopPath)" title="@Model.product_name"
    class="fancybox" rel="fancybox">
                        <img src="@Url.Content("~/Content/images/" + @Model.thumbImagePath)"  title="@Model.product_name"
    alt="@Model.product_name" id="image" />
                    </a>
                </div>
                @if (Model.imagePaths.Count() > 0)
                {
                    <div class="image-additional">
                        @foreach (var item in Model.imagePaths)
                        {
                            <a href="@Url.Content("~/Content/images/" + @item.imagePopPath)" title="@Model.product_name" class="fancybox" rel="fancybox">
                                <img src="@Url.Content("~/Content/images/" + @item.imagePath)" title="@Model.product_name" alt="@Model.product_name"/>
                            </a>
                        }
                    </div>
                }
            </div>
            <div class="right">
                <div class="description">
                    @if (Model.manufacturer != null || Model.manufacturer != "")
                    {
                        <span>Brand: </span> <a href="@Model.manufacturer_id">@Model.manufacturer</a><br />
                    }
                    <span>Product Code: </span>@Model.model<br />
                    <span>Reward Points:</span> @Model.reward<br />
                    <span>Availability: </span>@Model.stock_status
                </div>
                <div class="price">
                    Price:
                    @if (Model.special == null || Model.special == "")
                    {
                        @Currency.format(Model.price, null, null, true)
                    }
                    else
                    {
                        <span class="price-old">@Currency.format(Model.price, null, null, true)</span>
                        <span class="price-new">@Currency.format(Model.special, null, null, true)</span>
                    }
                    <br />
                    <span class="price-tax">Ex Tax:
                        @if (Model.special != null && Model.special != "")
                        {
                            @Currency.format(Model.special, null, null, true)
                        }
                        else
                        {
                            @Currency.format(Model.price, null, null, true)
                        }
                    </span>
                    <br />
                    <span class="reward"><small>Price in reward points: @Model.points</small></span>
                    <br />
                    <br />
                    <div class="discount">