value not updated to textbox in Jquery of MVC3 vie

2019-09-20 03:56发布

问题:

I have this view

     @if (@Model.QuestionType == 5)
     {
      <div data-role="fieldcontain">
    @using (Html.BeginForm("SaveTextBox", "GetQuestion", Model))
    {
        @Html.AntiForgeryToken() 
        <fieldset data-role="controlgroup">
            <label for="select-choice-1" class="select">@Model.QuestionText
            </label>
            <br />
            @if (Model.Options != null)
            {
                foreach (var item in Model.Options)
                { 
                    <input type="text" id="textbox1" value="@item.OptionText" name="selectedObjects" />
                    <span id="username_warning" style="color: red"></span>  
                }
            }
            else
            {
                <input type="text" id="textbox1" name="selectedObjects" />
                <span id="username_warning" style="color: red"></span> 
            }
            <br />
            @if (Model.Validations != null)
            {
                <input type="hidden" id="hiddenvalidations" value="@Model.Validations" />
            }
        </fieldset>
        <p>
            <input type="submit" id="textboxsubmit" value="Next" />
        </p>
        }
</div>
}

i am redirecting to the same view based on questiontype. so this loaded whenever of questiontype =5 comes.

i am reading the values in JQuery as

     $("#textboxsubmit").live("click", function () { 
        var textvalue = $("#textbox1").val(); 
        textvalue = jQuery.trim(textvalue);
        var validations = $("#hiddenvalidations").val();
    alert(textvalue);
    alert(validations);
   });

I am reading this values and validating the data.

its everytime giving the first loaded textbox value. why its not updating in Jquery.

whats the issue with live. how do i solve it ?

回答1:

Do you mean this? textvalue = textvalue + jQuery.trim(textvalue);