Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a doubt in MVC that how can I display the name of a person instead of id in edit action method, the main thing is that I need to store the id in table so I created as int table but I need to display the name instaed of id for that I have written a code
var m = db.Example.Where(r => r.ID == id).Select(p=>p.FirstName);
in edit action method and I am getting the correct name instead of Id and to pass to the view page I pass this m to Viewbag ie,
ViewBag.name = m;
. here the name gets the correct value which I need . Now my doubt is when I pass this value to edit view page the editor field is blank and can see up and down arrow at the end of this editor field
@Html.EditorFor(model => model.NameId,null, new { htmlAttributes = new { @class = "form-control", @Value = ViewBag.name} })
I need to just display the name . how can it be possible? can anyone please help to fix my problem.

What I have tried:

I have tried many times and I didn't find how to solve this problem
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900