E.Hamed E.Hamed - 1 month ago 8
jQuery Question

How to send a user choice from a controller view to another?

I have three divs like this:

<div onclick="GoToContactPage()">
@*Some Code*@
</div>
<div onclick="GoToContactPage()">
@*Some Code*@
</div>
<div onclick="GoToContactPage()">
@*Some Code*@
</div>


on the
GotoContactPage()
function I only have a redirect link to another view like that

function GoToContactPage() {
window.location.href = '/Home/SecondView';

}


and in that
/SecondView
I have an input method like that:

<div class="col-md-5">
@Html.TextBoxFor(m => m.Name, new { placeholder = "Name", @class = "form-control", @id= "name"})
</div>


All I was trying to do, when the user choose the first div a specific text appears in the input method in the other view, and so to the another two divs. I was thinking about sending an int then having an if statements and also was thinking about sending the string itself in the OnClick function but don't know what to do? and which is better? What should I do, Please?

Answer

You should pass an id in GoToContactPage(id) so that function takes an argument an run according to it.

function GoToContactPage(id) {
    if(id== ""){
       //your conditions
    }else if(id ==""){
       //your conditions
    }else{
       //your conditions
    }
}

To get data in Second page pass it through the url www.example.com?id=1&name=xyz and get them on second page by $_GET method.