如何在Mvc 4中编辑现有记录并从不同字段添加新记录? [英] How Do I Edit Existing Record And Add New Record From Diiferent Field In Mvc 4?

查看:81
本文介绍了如何在Mvc 4中编辑现有记录并从不同字段添加新记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的页面例如

学生姓名:文本框



科目标记



C ++ [复选框]文本框

Java [复选框]文本框



提交



如果我来这个页面进行编辑然后如果我选择两个复选框然后现有记录说C ++记录应该更新而Java记录不在数据库中那么它应该在db中添加..

i试过但我只能进行编辑但是没有添加新记录...

任何人都可以帮助plz ??

I have page like this e.g.
Student Name: textbox

Subjects Marks

C++ [checkbox] textbox
Java [checkbox] textbox

submit

if i come on this page for edit then if i select two checkbox then existing record say C++ record should get updated and Java record is not in Database then it should get added in db..
i tried but i can only able to get edited but the new record is not added...
Can anyone help plz??

推荐答案

您应该提供更多信息(例如来自您的控制器的源代码),但是假设您正在使用Entity Framework并且您的表(和EF类)具有ID,那么在控制器中您需要测试数据它的ID来自视图,如果ID为0则表示新数据,您应该通过使用相关的主题标记EF实体中的新记录来管理这种情况AddObject()方法,最后使用SaveChanges()。
You should provide more info (source code from your controller for example), but supposing you are using Entity Framework and your tables (and EF classes) have IDs, the ideea is that in the conttroller you have to test the data that that come form the view by its ID, if the ID is 0 means new data and you should manage this case by adding the new record in the associated "Subject Marks" EF entity by using "AddObject()" method, then at the end to use "SaveChanges()".


这篇关于如何在Mvc 4中编辑现有记录并从不同字段添加新记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆