0

I need to pass textbox input value and dropdownlist selected value to Controller in MVC4 ????????? For Eg : I have a Form with Textbox and Dropdownlist and a ( PartialView For Webgrid) . When i give datetime input to Textbox and Selected the "DoctorName" in Dropdown . Then i need to pass textbox input value and dropdownlist values as parameters to the controller ??????? My Controller is used to bind the webgrid in PartialView... The Code i tried which is not working......#doctortype is dropdownlist,#AppointmentDate is Textbox input datetime.

jquery:

   <script type="text/javascript">
    $(document).ready(function () {

        $('#doctorType').change(function (e) {
            e.preventDefault();
            var url = '@Url.Action("Filter")';
            $.get(url, { doctorname: $(this).val() }, { AppointmentDate: $('#AppointmentDate').val() }, function (result) {

                $('#FilterWebgrid').html(result);
            });
        });
    });
</script>
1
  • Are you using @Html.Dropdownlistfor ? Textbox and dropdown value binded to model ? Commented Nov 21, 2013 at 12:36

2 Answers 2

1

is not

$.get(url, `{ doctorname: $(this).val() }, { AppointmentDate: $('#AppointmentDate').val() }`, function (result) {

                $('#FilterWebgrid').html(result);
            });

You are sending two object. You have to send a single object like this:

  $.get(url, { doctorname: $(this).val(), AppointmentDate: $('#AppointmentDate').val() }, function (result) {

                $('#FilterWebgrid').html(result);
            });

2) check the console and network tab and check if there is any error.

3) The value you are passing must be the same type as the parameter expected in the Action

Sign up to request clarification or add additional context in comments.

Comments

0

This is just simple method to post data. If your controller returns data back to view, try $.getJSon();

<input type="text" value="doctor name" id="txtDoctor"/>
<select id="ddlDoctor"><option>SomeSelectedData</option></select>

<script>
 $(document).ready(function() {
   var txtValue = $('#txtDoctor').val();  
   var ddlValue = $('#ddlDoctor').val();

   $.ajax({
       url: '/controller/action',
       data: { doc: txtValue, name: ddlValue },
       traditional: true,
       success: function(result) {
       alert(result.status);
   }
 });
 });
</script>

to know more about getJSon and JSON Result, check these links.

GetJson with parameters

JSON result in view

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.