asp.net mvc - Working on view with two forms on one controller in mvc 5 -
i have 1 drop down box. based on selected item of dropdownbox want generate form below on same view, please find code below.
[httpget] public actionresult binddropdown() { viewbag.doctype = new selectlist(db.doctypemasters, "id", "doctypename"); return view(); } [httppost] public actionresult binddropdown(string doctype) { string doc = doctype.trim(); return view(); } this view code
@model c3cardkyc.models.doctypemaster @{ viewbag.title = "binddropdown"; } <h2>binddropdown</h2> <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $('#myidandname').change(function () { var doctype = $("#myidandname option:selected").text(); alert(doctype); $.ajax({ url: '@url.action("binddropdown", "document")', type: 'post', data: { doctype: doctype }, success: function (result) { alert('success') } }) }); }); </script> <fieldset> <legend>doctypemaster</legend> @*select document type: @html.dropdownlist("doctype", "select");*@ @html.dropdownlist("myidandname", viewbag.doctype selectlist, " -- select document type -- ") </fieldset> <p id="hi"> @html.actionlink("back list", "index") </p> <div id="hi"> @using (html.beginform("binddropdown", "document", formmethod.post, new { id = "submitform" })) { <fieldset> <ol> <li> @html.labelfor(model => model.doctypename) @html.textboxfor(model => model.doctypename, new { maxlength = 50 }) @html.validationmessagefor(model => model.doctypename) </li> </ol> <button type="submit" id="btnsave" name="command" value="save">save</button> <button type="submit" id="btnsubmit" name="command" value="submit">submit</button> <button type="submit" id="btncancel" name="command" value="cancel" onclick="$('#submitform').submit()">cancel (server side)</button> </fieldset> } </div> when run below error coming. there no viewdata item of type 'ienumerable' has key 'myidandname'.
and if select item frm dropdown below form should appear. please suggest
Comments
Post a Comment