我正在使用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响应
最佳答案
当使用@ko.html.button时,我们必须从如下控制器方法返回json对象。
public ActionResult AddAddress()
{
return Json(new { Url = Url.Action("Stock", "Inventory") });
}
关于c# - KnockoutMVC提交按钮不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28190277/