Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:37:18+00:00 2026-06-11T20:37:18+00:00

In my application I have a common layout for all the views, from one

  • 0

In my application I have a common layout for all the views, from one of the view(Index.cshtml) i have used Ajax.BeginForm to display another view as a response the code for this is

@using (Ajax.BeginForm("Edit", "Home", new AjaxOptions { UpdateTargetId = "content",InsertionMode=InsertionMode.Replace }))

now my problem is as a response the edit view is rendered as expected but the script block with in the edit view is not included and hence the javascript is not executed.

@model Test.Models.CARE
@{
ViewBag.Title = "Edit";
}
<script>
function s() {
alert("hi");
}
</script>
<h2 style="padding: 0px; margin-top: 0px;">
Edit</h2>

@using (Html.BeginForm("SaveForConfirmation", "Home"))
{

Plz help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:37:19+00:00Added an answer on June 11, 2026 at 8:37 pm

    It’s bad practice to put javascript code in views, let alone partial views. So I would recommend you to externalize this javascript code in a separate function in a separate javascript file.

    And then you could subscribe to the OnSuccess event of the Ajax.BeginForm helper:

    @using (Ajax.BeginForm("Edit", "Home", new AjaxOptions { OnSuccess = "editSuccess", UpdateTargetId = "content", InsertionMode = InsertionMode.Replace }))
    {
        ...    
    }
    

    and then define the editSuccess function in a separate javascript file:

    function editSuccess(result) {
        alert('hi');
    }
    

    now in your partial view you should leave only what is supposed to be in a partial – markup. Get rid of any <script> tags, you don’t need them. You don’t need any inline scripts. They only increase the size of your webpages and waste bandwidth as they cannot be cached by the browsers:;

    @model Test.Models.CARE
    <h2 style="padding: 0px; margin-top: 0px;">Edit</h2>
    @using (Html.BeginForm("SaveForConfirmation", "Home"))
    {
        ...
    }
    

    UPDATE:

    If you have some poorly written javascript that depends on crap like ViewBag inside the partial then you could invoke the corresponding function from within the OnSuccess callback:

    @using (Ajax.BeginForm("Edit", "Home", new AjaxOptions { OnSuccess = "s", UpdateTargetId = "content", InsertionMode = InsertionMode.Replace }))
    {
        ...    
    }
    

    Notice how I have defined OnSuccess = "s" where s is the function that you have defined in your partial and which will be invoked in this case. But I repeat once again, this is a wrong approach and should only be used if you don’t have time to refactor your code properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our application there is a basic layout for all views. To reuse common
In my Android application I have to use common string value for all activities.
It's common to have an object used application wide. What are the different patterns
We have a web application with a common header file for all pages. We
I have an application with a common Header in all layouts. I want that
Within my iPhone application I have a common tab bar with three tabs that
I have a Client/Server application, where the Client and Server have some common tables
In a typical business application it is quite common to have forms that are
I have a web application that uses a library which resides in TOMCAT_HOME/common/lib. This
I have Spring web application. I would like to put some common piece of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.