1

I have MVC4 application which contains views and partial views.

1) View Pages (Home.cshtml,Index.cshtml)

2) PartialViews(View1.cshtml,View2.cshtml,View3.cshtml)

3) I have 3 buttons(Button1,Button2,Button3) in www.example.com/Home page

The buttons are

<button id="btn1" type="button" onclick="btn1Click(this);"> View1 </button>
<button id="btn2" type="button" onclick="btn2Click(this);"> View1 </button>
<button id="btn3" type="button" onclick="btn3Click(this);"> View1 </button>

When click on these buttons I display those respective partial views in the Home page(content section). I wrote that code in Javascript function(btn1Click(button)) in .js file. Incase if we have more number of partial view to display in the content of home page, then how can we track the Path(our project file path) of those partial views using jQuery/Javascript. If we use

Window.location.href

we will get the main url(www.example.com/Home page), but when user click on those buttons(button1/button2/button3) I need to find the partial view path nothing but project path (ProjectName/PartilaViews/View1.cshtml) or (ProjectName/PartilaViews/View2.cshtml) or (ProjectName/PartilaViews/View3.cshtml) using jQuery/Javascript.

I don't want to change the functionality / procedure(above process),

2 Answers 2

0

Try this :

window.location.href='@Url.Action("action name", "controller name")'

and actionresult from ur controller will return partial view.

-------------------------------------------------------------OR------------------------------------------------------------------

var partial = '@Html.Partial("Partial view name")'

the variable partial will have the html returned from partial view.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your quick reply, Yah it is correct but I need to Implement / get the path using pure(not using any C#/Razor syntax) jQuery/Javascript. The controller name is anything and partial view is anything my Javascript/jQuery need to be work for all the controllers/views.
i m not getting ur qusetion @Surya The controller name is anything and partial view is anything means???
I will write that javascript/jQuery code in xyz.js file and in that code I place an alert(partialviewpath);. If I place that xyz.js in project1 then I will run that project, If any oprations like displaying partial view in the content is occur when click on button then my script will take care of that and display the project path(partialview path) in popup(alert I wrote in that code). Like this if I place that xyz.js file in any project it need to take care of those operations what I have specified in the above message and display partialview path in alert.
0

I got answer to my question. By using the below Code you can get the Project url path. but you will get all the url paths which are requesting from your website but you need to separate those url paths based on your requirement.

$(document).ajaxComplete(function (event, xhr, settings) {
        if (settings.type == "GET")
        {
            var vGETUrl = settings.url;
            alert(vGETUrl);
        }
});

The above code capture the "GET" requests from your website. You can go through the below url for more details

http://api.jquery.com/category/ajax/

Comments

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.