2012-10-22 8 views

Odpowiedz

88

można przekazać to w ten sposób:

Url.Action("CreatePerson", "Person", new RouteValueDictionary(new { id = id })); 

lub można również przejść tędy

Url.Action("CreatePerson", "Person", new { id = id }); 
+7

Co zrobić, jeśli kod znajduje się w javascript? 'window.refresh ({url: '@ Url.Action (" CreatePerson "," Person ", new {id = Id})", "-> ten kod ulega uszkodzeniu, ponieważ nie mogę tam przekazać zmiennej. działa na stałe: '@ Url.Action (" CreatePerson "," Person ", new {id =" someId "}) ',' -> Jak to działa? – chiapa

+0

Poszukuję również tej odpowiedzi –

+0

Jeśli funkcja znajduje się w pliku javascript, co można zrobić, to umieścić adres URL widoku w ukrytym polu, a następnie wywołać go przy użyciu javascript, np .: @ Url.Action ("CreatePerson", " Osoba ", nowy {id = Id}) <\input> Następnie wywołaj ją w javascript: $ (" # url "). Val(); –

0

należy przekazać go w ten sposób:

public ActionResult CreatePerson(int id) //controller 
window.location.href = "@Url.Action("CreatePerson", "Person",new { @id = 1}); 
2

ten sposób przekazać wartość z kontrolera do widoku:

ViewData["ID"] = _obj.ID; 

Oto sposób przekazać wartość z widokiem i sterownika powrotem:

<input type="button" title="Next" value="Next Step" onclick="location.href='@Url.Action("CreatePerson", "Person", new { ID = ViewData["ID"] })'" /> 
11
public ActionResult CreatePerson (string id) 

window.location.href = '@Url.Action("CreatePerson", "Person" , new {id = "ID"})'.replace("ID",id); 

public ActionResult CreatePerson (int id) 

window.location.href = '@Url.Action("CreatePerson", "Person" , new {id = "ID"})'.replace("ID", parseInt(id)); 
0
@Url.Action("Survey", "Applications", new { applicationid = @Model.ApplicationID }, protocol: Request.Url.Scheme) 
-2
public ActionResult CreatePerson(int id) //controller 

window.location.href = '@Url.Action("CreatePerson", "Person")?id=' + id; 

Albo

var id = 'some value'; 
window.location.href = '@Url.Action("CreatePerson", "Person", new {id = id})'; 
0

Jeśli używasz Url.Action wewnątrz JavaScript wtedy może

var personId="someId"; 
$.ajax({ 
    type: 'POST', 
    url: '@Url.Action("CreatePerson", "Person")', 
    dataType: 'html', 
    data: ({ 
    //insert your parameters to pass to controller 
    id: personId 
    }), 
    success: function() { 
    alert("Successfully posted!"); 
    } 
}); 
0

spróbować tej

publiczne ActionResult CreatePerson (string Enc)

window.location = „@ Url.Action ("CreatePerson", "osoba", new {Enc = "id", actionType = "Disable"}). "replace (" id ", id) .replace (" & "," & ");

otrzymasz identyfikator wewnątrz łańcucha Enc.

Powiązane problemy