- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以我是一个非常新的 MVC 开发人员,我在使用特定功能时遇到了一些麻烦。
我有这些类(class):
public class User
{
public int UserId{ get; set; }
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public bool LogicalDelete { get; set; }
public virtual ICollection<Phone> Phone{ get; set; }
public virtual ICollection<EventList> Event{ get; set; }
}
public class Phone
{
public int PhoneId{ get; set; }
public string Phone{ get; set; }
public bool Mobile{ get; set; }
public int UserId{ get; set; }
public virtual UserClass User { get; set; }
}
我想做的是,当我转到用户的“编辑” View 时,有一个按钮可以让我使用 AJAX 帖子向该特定用户添加新电话或以逗号分隔的多个电话脚本。
到目前为止,我一直将其用于单一电话方法:
function Add() {
var res = validate();
if (res == false) {
return false;
}
var ph = {
UserId: $('#UserId').val(),
FirstName: $('#Phone').val(),
LastName: $('#Mobile').val(),
};
$.ajax({
url: "/User/Edit",
data: JSON.stringify(ph),
type: "POST",
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (result) {
loadData();
},
error: function (errormessage) {
alert(errormessage.responseText);
}
});
并且,在 UserController
中:
public JsonResult Add(Phone ph)
{
return Json(myDb.Add(ph), JsonRequestBehavior.AllowGet);
}
我遇到的主要问题是我无法将特定的用户 ID 从编辑 View 模型传递到 Controller 。我通过将用户从 View 添加到数据库进行了一些测试,我能够做到,但是当我尝试访问导航属性时,我既无法列出电话,也无法添加新电话。
我错过了什么?
最佳答案
为什么不直接使用 Ajax 表单?
<div id="userDetails">
@* All other user details *@
@using (Ajax.BeginForm("AddPhone", null, new AjaxOptions()
{
HttpMethod = "Post",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "userDetails",
}, null))
{
@Html.HiddenFor(m => m.UserId)
<input type="text" id="phone" />
<select id="phoneType">
<option value="home">Home</option>
<option value="cell">Cell</option>
</select>
<button type="submit">Add Phone</button>
}
</div>
[HttpPost]
public ActionResult AddPhone(int UserId, string phone, string phoneType)
{
//Add phone using userId, phone, & phoneType
...
//Return view with model (user object) to update page with added phone
return View("UserView", UserObject);
}
关于c# - 使用 MVC 的 AJAX/jQuery 和 CRUD 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41155296/
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
我刚刚发现了这门语言,我想知道是否可以使用数据库制作基本的 CRUD 网络应用程序。 最佳答案 有 mysql 的库和 postgresql , 核心库提供了一个 web server支持 HTTP、
Symfony 4.0 发布后,不再支持 SensioGeneratorBundle .因此命令 php app/console generate:doctrine:crud不可用。 他们建议使用 M
在开发 Web 应用程序时,我通常会看到人们执行增删改查和同步 View 的两种方式。 这里是使用 ajax 的高级示例。 1-方法一 创建操作可能涉及 POST 请求,成功后只需执行另一个 GET
我已经成功地使用 Yii2 模型和 CRUD 生成器为我的网络应用程序获取了一些框架代码文件。特别是,CRUD Generator 声称已成功将其 View 文件创建到: /basic/views//
在我的项目中,我一直在使用 Django 的通用 CRUD View 来处理很多事情。我现在想开始迁移到 DJango 1.3 中基于类的新样式通用 CRUD View 。我没有发现这些文档有多大帮助
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题?通过 editing this post 添加详细信息并澄清问题. 7年前关闭。 Improve this
我希望标题不要太含糊,所以这里是: 我创建了一个 MySQL 数据库,其中存储了两个表:一个包含输入数据,另一个包含输出数据。 之后我编写了一个程序,连接到这个特定的数据库,从输入表中提取数据,解析它
我需要编辑我的实体以获得更多值。我已经用我之前的值生成了 crud。如何在编辑实体后通过应用程序/控制台重新生成 crud,以便它自动为其他值生成函数。 最佳答案 为此,您需要删除为此 crud 生成
因此,我仅使用 JavaScript 创建了一个简单的 CRUD 应用程序。现在,您可以将国家/地区添加到数组中并从数组中删除国家/地区。我希望能够编辑数组中的现有国家/地区,例如我想将“斯德哥尔摩”
我想让java中的一个类有一个可以与Hibernate配置交互并执行某些操作的方法,该方法被标识为ENUM(例如:读取,更新,添加,删除等) 方法参数应为(枚举操作、类 DTO、NamedQuery
我正在构建一个 React 应用程序,并使用 auth0 来登录/验证用户。 在使用 auth0 之前,我一直在对 API 进行 CRUD 调用来发布帖子。这又是在使用 auth0 之前、在我拥有用户
尝试使用 BlueJ 构建我的第一个 Java MySQL CRUD 应用程序。我可以运行该应用程序并将数据写入 MySQL 数据库。但是,当我运行搜索函数时,我得到了 Java .NullPoint
我正在试用 Microsoft Master Data Services,我想以编程方式将数据添加到数据库中。我开始获得模型/实体/成员结构,但我还不确定。如果您对此结构有很好的解释,请分享。 假设有
我正在尝试开发一个 Backbone Marionette 应用程序,我需要知道如何以最佳方式执行 CRUD(创建、读取、更新和销毁)操作。我找不到任何解释这一点的资源(仅适用于 Backbone)。
我已经根据文档和 medium article 模拟了与 Room 的多对多关系。 .使用这个@Relation,我可以从数据库中检索RecipeWithIngredients 或Ingredient
Closed. This question is opinion-based。它当前不接受答案。 想要改善这个问题吗?更新问题,以便editing this post用事实和引用来回答。 3年前关闭。
通过AngularJS通过REST进行CRUD操作的最佳实践是什么? 特别是这里的 Angular-Way 。我的意思是使用最少代码和最默认 Angular 设置来达到此目的的方式。 我知道$ res
我无法弄清楚我的更新功能。我能够从数据库中检索和删除,但我不知道如何更新。这对我来说是全新的,所以我很困惑。 .js 文件 //update user $("#btnUpdateUser").clic
我正在寻找一种对用户透明的 CRUD 操作后重新加载页面的方法。 实际上,在创建或删除之后,我必须重新加载页面才能显示我的操作。 我使用 api 来实现这个,当我将它与 json 文件一起使用时,它工
我是一名优秀的程序员,十分优秀!