Is there any better approach than what I am currently doing here:
MVC Controller action creates a select list as:
ProductsDDL.Select(rp => new SelectListItem
{ Value = Model.RawMaterialID.ToString() + "," + plant, Text = Model.FinishedProductName });
And HTML rendered as:
<select id="Products" name="Products">
<option value="3,PLANT1">Finished Product1</option>
<option value="4,PLANT2">Finished Product2</option>
<option value="7,PLANT3">Finished Product3</option>
</select>
On selection change, I use Jquery $.GetJSON to populate another drop down list. The reason I am concatinating PlantID with RawMaterialID is to avoid long query processing time.
On Post to action(string RawIDPlantID), I use Split(‘,’) to get RewMaterialID & PlantID
Other options are to use session to hold PlantID or input hidden field in MVC view.
I typically stay away from using commas as a delimiter in values that represent a single entity, and save the commas delimiting a list of multiple ids. In cases such as yours, I end up using an underscore. Then, should I need to comma separate a list of the IDs, it’s easier on the eyes and to parse. But that’s completely subjective and up to you, as the developer.
For example
is easier to eyeball
And that was as much criticism as I could muster about your code. The rest of it I’d use, and have used in the past.