如何从SQL视图中检索值并更新MVC中的表中的值 [英] How to retrieve values from SQL view and update values in table in MVC

查看:77
本文介绍了如何从SQL视图中检索值并更新MVC中的表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我开发了项目屏幕,我在数据库中创建了两个表格的视图,并从视图中检索值以更新值。



但它出错了:

传入字典的模型项目是telecom.models.itemrates类型,但这个字典需要一个模型项目类型telecom.models.vw_items



我尝试过:



型号:

公共类Vw_Items

{

public int Id {get;组; } $ / $
公共字符串RateCode {get;组; }

公共字符串ItemCode {get;组; }

[DisplayName(Item Name)]

公共字符串ItemName {get;组; } $ / $
[DisplayName(Item Type)]

public string ItemType {get;组; }

public string UOM {get;组; }

[必填]

[DisplayName(单价)]

公共小数? UnitPrice {get;组; }

}

控制器:



[HttpPost]

public ActionResult Edit (ItemRates itemrates)

{

if(ModelState.IsValid)

{

db.Entry(itemrates) .State = EntityState.Modified;

db.SaveChanges();

返回RedirectToAction(Index);

}

return View(itemrates);

}

查看:

@model Telecom.Models.Vw_Items

Dear Friends,

I have developed items screen, i created view with two tables in database and retrieve values from view to update the values.

But it makes an error:
The model item passed into the dictionary is of type telecom.models.itemrates, but this dictionary requires a model item of type telecom.models.vw_items

What I have tried:

Model:
public class Vw_Items
{
public int Id { get; set; }
public string RateCode { get; set; }
public string ItemCode { get; set; }
[DisplayName("Item Name")]
public string ItemName { get; set; }
[DisplayName("Item Type")]
public string ItemType { get; set; }
public string UOM { get; set; }
[Required]
[DisplayName("Unit Price")]
public decimal? UnitPrice { get; set; }
}
Controller:

[HttpPost]
public ActionResult Edit(ItemRates itemrates)
{
if (ModelState.IsValid)
{
db.Entry(itemrates).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(itemrates);
}
View:
@model Telecom.Models.Vw_Items

推荐答案

Quote:

传入字典的模型项目是telecom.models.itemrates类型,但是这个字典需要一个类型为telecom.models.vw_items的模型项

The model item passed into the dictionary is of type telecom.models.itemrates, but this dictionary requires a model item of type telecom.models.vw_items



直接问题,在编辑动作中更改参数类型


straight forward issue, change the parameter type in the Edit action

[HttpPost]
public ActionResult Edit(Vw_Items  item)
{


这篇关于如何从SQL视图中检索值并更新MVC中的表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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