2014-10-27 95 views

回答

0

具有HTML

<input type='text' id='mytxt' /> 
<div id='details'> </div> 

你會怎麼做:

$('#mytxt').change(function(){ 
    $.post('<%:Url.Action("Details")%>', { id: $(this).val()}, function(result){ 
     $('#details').html(result); 
    } 
}); 

和MVC中的作用是這樣的:

public ActionResult Details(string id) 
{ 
    //get the content somehow 
    ... 
    return Content(thecontent);  
} 
+0

我是一個asp.net mvc的新手,但我很緊急在這方面。你可以做一個更具體的例子,不要感謝你。我那時做過了,但它仍然不適合我 – 2014-10-28 03:58:09

0

您可以使用jQuery的事件的內容()方法來進行ajax調用,當文本框失去焦點時將返回一個局部視圖(即按下tab或另一個輸入元素被聚焦)。