c# - 尝试更新记录时出现 AngularJS 错误

标签 c# oracle angularjs

我刚开始学习angularjs,一直卡在保存记录上。我有一个带有文本框的表单,用于输入状态、companyId 和费率,这些文本框已预先填充了选定记录的数据。当我单击“保存”按钮时,我得到“POST ~/AppWeb/AppApi/UpdateRecord 404(未找到)”。我正在使用 Oracle 数据库。我有以下代码:

.js:

.factory("Services", function (Api) {           
this.saveRecord = function (data) {
    if (data.Id > 0) {
        return Api.save("AppApi/UpdateRecord", data);
    }
};  
return this;
})

.controller("ViewSaveController", function ($scope, $routeParams, $location, State, Services) {
Services.getRecord($routeParams.id).success(function (d) {
    $scope.model = d;
});

$scope.save = function (controller) {
    Services.saveRecord($scope.model).success(function (d, s, h, c) {
        //redirect to the list view
    });
};  
})

ApiControllder.cs:

public WorkRates UpdateRecord()
{
try
{
    var q = new DemoQueries();
    return q.UpdateRecord();
}
catch (Exception ex)
{
    return null;
}
}

PartialQueries.cs:

public WorkRates UpdateRecord(int id, string state, string companyId, string rate)
{
var sql = "update ratestable set state = :state, companyId= :companyId, rate = :rate where id = :id";
var db = Db.Load(sql);

db.AddParameter(":id", id);
db.AddParameter(":state", state);
db.AddParameter(":companyId", companyId);
db.AddParameter(":rate", rate);

db.DoExecute();

var l = db.GetList<WorkRates>().FirstOrDefault();
return l;
}

我不确定为什么会收到此错误消息。感谢您的帮助。

最佳答案

您收到 404 错误或 Not Found 错误,因为您的表单正在执行的 POST 没有到达您的网络应用程序的任何有效端点。基本上端点“AppWeb/AppApi/UpdateRecord”不存在。

您是否尝试过在您的代码中用“AppApi/UpdateRecord”替换“ApexApi/UpdateRecord”? 我不是 Angular 专家,但看起来这是路线问题。这篇文章可能会有所帮助。 http://viralpatel.net/blogs/angularjs-routing-and-views-tutorial-with-example/

关于c# - 尝试更新记录时出现 AngularJS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21767269/

相关文章:

angularjs - 超时在 AngularJS Karma 中不起作用 - Jasmine 测试

c# - 缺少实现该功能的UFL u212com.dll

c# - 如何从 excel 在 C# 中填充数据表

c# - 构造一个整数数组来实现特定的序列

sql - 使用 BREAK ON 命令时连接字段

javascript - JS 函数声明不应放在 block 中

c# - 如何在 Entity Framework 中将mysql中的char列类型作为字符串获取

java - 使用 JDBC 连接到 oracle 从插入语句返回 ROWID 参数

oracle - ORA-01658 : unable to create INITIAL extent for segment in tablespace TS_DATA

javascript - Angular 日期范围过滤器不起作用