tags:

views:

22

answers:

2

Hi,

How do i update textbox using MVC Ajax UpdateTargetId option.?

I am new to MVC Ajax applications. Please any one help me out.

Thanks, Pon Kumar Pandian .T

A: 

You can simply wrap all you want to update in some div with id same that you're putting in UpdateTargetId property, and return new content(new textbox with new value). And also don't forget to set Ajax updating type to replace(not append).

mmcteam.com.ua
Actually you are wrong.If you use UpdateTargetId , it will replace the whole innerHtml. This is cant be done. May be you please share some sample code for better understand your answer.
Pon Kumar Pandian
Yes, just return that textbox With new value one more time. And better put it to render partial to not repeat yourself.
mmcteam.com.ua
I think your worng. I will post answer for this question which i have tried.
Pon Kumar Pandian
It is not the best way but it is simplest way and it works! Of course you can return json in your controller then just update textbox value via jQuery.
mmcteam.com.ua
A: 

We can't give the textbox control id directly in UpdateTargetId property. Bur we can do work around to achieve this. Please fine the blow mention code for the same.

//This the call back method once the ajax request has been successes.

function fnOnSuccess(context) {

        alert(context); //this context having all the current ajax req & res information.

        var response = context.get_data(); //Using this get_data() method we can get the response from server.

        $('#txtajaxResponse')[0].value = response;    
    }

<%=Ajax.ActionLink("TextBox in UpdateTargetId","GetInfo","Ajax",new AjaxOptions{OnSuccess = "fnOnSuccess"}) %>

<%=Html.TextBox("txtajaxResponse")%>

Thanks, Pon Kumar Pandian .T

Pon Kumar Pandian