Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i trying this but in output its simply displaying text not as dropdown

What I have tried:

JavaScript
var table = document.getElementById("tablett");


                  var ddlfront = '<select id="ddlsubject" name="Subjects">';
                  var ddlback = '</select>';
                  //var ddls = 'Html.DropDownList("Subjects", new[] { new SelectListItem { Text = "Select Subject", Value = "Select subject", Selected = true } })';
                   var ddls = 'Html.DropDownListFor(model=>model.Subid, new[] {  new SelectListItem { Text = "Select Subject", Value = "Select Subject", Selected = true }})';
                  
                  for (var i = 0; i < jobj.length; i++) {
                      // Create an empty <tr> element and add it to the 1st position of the table:
                      var row = table.insertRow(0);
                      // Insert new cells (<td> elements) at the 1st and 2nd position of the "new" <tr> element: id = "txtdatepicker3",
                      var cell0 = row.insertCell(0);
                      var cell1 = row.insertCell(1);
                      var cell2 = row.insertCell(2);
                      var num = i;
                      //cell0.innerHTML = '@Html.TextBox("Date", string.Empty, new { @style = "width:150px;", @class = "date-picker" })';
                      cell0.innerHTML = '<input class="date-picker" id=' + i + ' name="Date" style="width:150px;" type="text">';
                      content = '<option selected="selected" value=select Subject >select subject</option>';
                      $.each(jobj, function (index, obj) {
                          alert(obj.Sname + obj.Sid);
                          //content += '<option selected="selected" value=' + obj.Sid + ' >' + obj.Sname + '</option>';
                          //                              cell2.innerHTML = '<option value="' + obj.Sid + '">' + obj.Sname + '</option>';
                          // $('#ddlsubj').append('<option value="' + obj.Sid + '">' + obj.Sname + '</option>');
                          ddls += '<option value="' + obj.Sid + '">' + obj.Sname + '</option>';
                          alert("one item added ");
                      });

                      // content += '<option selected="selected" value=select Subject >select subject</option>';
                      var opt = ddls; // ddlfront + content + ddlback;
                      //var opt = ddls + content;
                      cell1.innerHTML = opt;
                      cell2.innerHTML = opt;
Posted
Comments
F-ES Sitecore 17-Aug-16 7:17am    
The .net code (Html.DropDownListFor) runs on the server when the html to send to the client is being generated. The client (browser) then gets that html and executes it. So you can't have client-side js interact with server-side concepts like the Html helper.

If you explain what it is you're trying to achieve someone may be able to explain what it is you need to do.
RAJU-11052090 17-Aug-16 7:25am    
thank you very much for replying

I have two table consider order and order details table in db.
in my scenario,I have to insert both the table .i have achived the order table insertion but orderDetails tables has got multiple records and i got stuck here .
RAJU-11052090 17-Aug-16 7:28am    
I have also checked inserting multiple records ,got solution. but in my case i am using a model object as a parameter for controller [HttpPost]create method.so i can't use list
RAJU-11052090 17-Aug-16 7:31am    
var res = new List<tblTTdetail> {tblttdetail};
using this i have converted my model object into list and applied foreach loop for that and everything working fine till here,but problem is, i am adding html select and its returning null value so tot of adding @HTML.DropDownListFor by javascript function

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