如何在视图中将viewbag值从控制器传递给html.editor helpermethod [英] How to pass viewbag value from controller to html.editor helpermethod in view
问题描述
我怀疑如何将值从viewbag传递到view页面。我从表中获取值并传递给viewbag,但在视图页面中它没有返回我需要的数据
I have a doubt that how can I pass the value from viewbag to view page. I am taking the value from table and passing to viewbag but in the view page it is not returning the data which I need
var t = db.Names.Where(r => r.ID == id).Select(i=> new { i.ID, i.FirstName });
ViewBag.name= t;
查看页面中的
in view page
@Html.Editor("name", new { htmlAttributes = new { @class = "form-control" } })
如果我需要名字为abc它在控制器中正确返回,但未在视图页面中显示。 ID和Name显示为ID和Name本身但是如何将此值传递给查看页面
如何在编辑器字段中获取文本值,但在内部它以int的形式存储值。有人能帮帮我吗?
我尝试过的事情:
我找到了结果,但没有得到完美的结果
If I need the name as abc it is returning correctly in controller but is not showing in view page. the ID and Name are showing as ID and Name itself but how to pass this value to view page
how can I get the text value in editor field but internally it is storing as int that is the value. can somebody help me ??
What I have tried:
I have seach for the result but didn't get the perfect one
推荐答案
通过
Pass
@ViewBag.name
而不是
instead of
"name"
到编辑器
to the editor
这篇关于如何在视图中将viewbag值从控制器传递给html.editor helpermethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!