2

At the moment I have a MasterPage in an ASP.NET MVC3 project with a animesearch function

function AnimeSearch() {
                alert(document.getElementById('anime').value);
                window.location = "Paging/AnimeBySearch?searchstring=" + (document.getElementById('anime').value);
            }

What I do , I type in an anime movie in an html input tag and it returns the correct values accordingly.

As one can see , is that my JavaScript function is calling my controller and then the function with the correct parameters(from the input).

However a couple of questions.

First since this function is on my masterpage and the controller call is pretty static the following of course happens. When I get my result after for instance searching for "naruto" I am in the paging controller. If I want another anime movie then of course because of my static location the controller does not work anymore. This is my first question , what is the cleanest and proper way of handling this(no hacks please , did that , works but is not good coding )?

Second Is my approach correct ( calling the controller and action like this from javascript )?

2 Answers 2

2
function getBaseUrl()
{
   return "@Url.Content("~/")";
}

function AnimeSearch(baseUrl) {
   alert(document.getElementById('anime').value);
   window.location = getGetBaseUrl() + "/Paging/AnimeBySearch?searchstring=" +     (document.getElementById('anime').value);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer this indeed does look like it would work , I'll try it later.
0

i would suggest that you think about a rewrite of the implementation and setup a controller and view that queries the anime model. this controller would implement an action method that allowed for paging and would return a partialview that was emitted into a predefined div on your anime search view. i'm in transit on iphone at present, otherwise would leave code example.

will update when on terra firma...

1 Comment

My Paging Controller has the view(AnimeBySearch). This action method also allows for paging. So I'm a bit confused as to what you mean exactly, however I do get a bit of a feeling of what you mean with the partial view and it definately feels like this is the way I would like to go. If you could be more specific , it would really help me out. Thanks btw!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.