This is a migrated thread and some comments may be shown as answers.

ViewData name cannot be the same as ComBoxFor id name

2 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Francis
Top achievements
Rank 1
Francis asked on 22 Nov 2017, 07:30 PM

While populating a ComboBoxFor to be inside a grid, if the name of the view data variable is the same as the id, validation will be ignored.

View:

columns.ForeignKey(p => p.JobNo, (System.Collections.IEnumerable)ViewData["JobNo"], "JobNo", "JobNumber");

Controller:

public IActionResult Index()
       {ViewData["jobnumber"] = _ddservice.GetAllOrdersByOfficeIdDD(oid);
           return View();
       }

 

2 Answers, 1 is accepted

Sort by
0
Francis
Top achievements
Rank 1
answered on 22 Nov 2017, 07:35 PM

Page was submitted before I finished....
 

Controller should be this:

public IActionResult Index()
        {
            ViewData["jobno"] = _ddservice.GetAllOrdersByOfficeIdDD(oid);
            return View();
        }

 

If ViewData["JobNo"] is used, the grid makes no validation on the field. If you change the name to ViewData["jobnumber"], the validation works.

0
Stefan
Telerik team
answered on 27 Nov 2017, 09:10 AM
Hello, Francis,

We do recommend using different names in this scenario as the ViewData should refer to a collection instead of single value as the ID field.

As the name of the ViewData collection is custom, modifying it should not cause changes to the end result.

Still, I will forward this to the developers' team for further investigation to check if we can improve this scenario.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Francis
Top achievements
Rank 1
Answers by
Francis
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or