2011-06-16 5 views
0

J'utilise un bouton de lien d'action mon projet et en utilisant une fonction Javascript aussi. qui met à jour ma vue partielle 2 mais quand je cours mon projet Cela me donne une erreur.Problème avec le paramètre de passage et le paramètre de réception en javascript Fonction

Le nom 'temp' n'existe pas dans le contexte actuel

   <%= Ajax.ActionLink("Select", "Employee", new { Id = Employee.EmployeeID }, newAjaxOptions { UpdateTargetId = "Employee",HttpMethod="Post", OnSuccess = "EmployeeHistory('" + Employee.EmployeeID.ToString() + "')" })%> 

et laisser la fonction javascript je suis appeler est comme

 <script language="javascript" type="text/javascript"> 
     function EmployeeHistory(EmployeeID) { 
     $('#EmployeeInformation').load('<%= Url.Action("EmployeeInformation", "Home",new { Id=EmployeeID}) %>'); 
     } 

     function success(result){ 
     $("#EmployeeInformation").html(result); 

Répondre

0

Vous ne pouvez pas mélanger côté serveur code avec javascript comme ceci (Url.Action fonctionne sur le serveur tandis que EmployeeID est une variable javascript):

$('#EmployeeInformation').load('<%= Url.Action("EmployeeInformation", "Home",new { Id=EmployeeID}) %>'); 

les opérations suivantes:

var url = '<%= Url.Action("EmployeeInformation", "Home") %>'; 
$('#EmployeeInformation').load(url, { id: EmployeeID })); 

Aussi, vous devez définir l'OnSuccess comme ceci:

OnSuccess = "function() { EmployeeHistory('" + Employee.EmployeeID.ToString() + "'); }" 

Mais je tout à fait tout à fait honnêtement utiliser jQuery avec une Html.ActionLink norme aide et faire choses: discrètement

<%= Html.ActionLink(
    "Select", 
    "Employee", 
    new RouteValueDictionary(new { id = Employee.EmployeeID }), 
    new Dictionary<string, object> { 
     { "id", "selectEmployee" }, 
     { "data-id", Employee.EmployeeID } 
    } 
) %> 

puis j'AJAXify il discrètement:

<script type="text/javascript"> 
    $(function() { 
     $('#selectEmployee').click(function() { 
      var link = $(this); 
      $.post(this.href, function(result) { 
       $('#Employee').html(result); 
       var url = '<%= Url.Action("EmployeeInformation", "Home") %>'; 
       $('#EmployeeInformation').load(url, { id: link.data('id') }); 
      }); 
      return false; 
     }); 
    }); 
</script> 
+0

je pense qu'il attend employeeid de la signature de la fonction js EmployeeHistory (EmployeeID) et ayant problème en passant cette param les options ajax –

+0

Merci Darin Dimitrov Il a commencé à travailler –

Questions connexes