我正在使用knockoutmvc绑定控件。(http://knockoutmvc.com/)
点击按钮时出现以下错误。
以下是我的Razor视图实现:
@using PerpetuumSoft.Knockout
@model OpManWeb.ViewModel.ManageAddressVM
@{
var ko = Html.CreateKnockoutContext();
}
@{
ViewBag.Title = "Manage Addresses";
}
@Scripts.Render("~/customjs")
@Scripts.Render("~/knockout")
<div class="container-fluid zeropadding" style="margin-top:15px; width:100%; font-size:13px;">
<div class="row">
<div class="col-md-3 col-lg-3 clmargin">
<div class="form-group col-md-4 zeropadding div1adjustments">
@Html.LabelFor(m => m.IndexNo, new { @class = "fieldtext" })
</div>
<div class=" form-group col-md-8 div2adjustments ">
@ko.Html.TextBox(m => m.IndexNo, new { @class = "form-control input-sm fieldtextinput " })
<input type="reset" class="btncross" data-toggle="tooltip" title="Click to clear" value="X" />
<button type="button" class="btn btn-search searchbtn" data-toggle="tooltip" data-placement="bottom"
title="Search customer as per Index No">
<i class="fa fa-search"></i>
</button>
</div>
</div>
<div class="col-md-2">
@ko.Html.Button("Add Address", "AddAddress", "Customer", null, new { @class = "btn btn-large btn-primary" })
</div>
</div>
</div>
以下是CustomerController文件的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ServiceStack.Mvc;
using OpManWeb.Models;
using PerpetuumSoft.Knockout;
using OpManWeb.ViewModel;
using MvcJqGrid;
namespace OpManWeb.Controllers
{
public class CustomerController : KnockoutController
{
public ActionResult AddAddress()
{
AddressVM addressVM = new AddressVM();
addressVM.selectmode = Mode.Add;
return View("AddEditAddress", addressVM);
}
}
}
以下是错误Html响应
答案 0 :(得分:3)
使用@ Ko.Html.Button时,我们必须从控制器方法返回Json Object,如下所示。
public ActionResult AddAddress()
{
return Json(new { Url = Url.Action("Stock", "Inventory") });
}