.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Injecting a Script into the View from the Controller

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net

I want to Injecting a Script into the View from the Controller on postback. How do you do it. Is there a RegisterClientScript equivalent?

View Complete Post

More Related Resource Links

Model View Controller (MVC) for ASP.NET

Model View Controller (MVC) architectures, immediately wonder how the MVC pattern can be applied in an ASP.NET world. This article will demonstrate how the MVC pattern can be applied to an ASP.NET web application and still maintain the basic Microsoft supplied architecture.

Is it bad MVC practice to return a view of a different controller?

I came upon this when had problem trying to return a view of a different controller.  In controller1, I have view view1.In Action1 of controller2, I wanted to do something like:public ViewResult Action1(){     return View("/Controller1/View1");}but, found out, I couldn't do it.  So I searched and found this: http://stackoverflow.com/questions/879852/asp-net-mvc-display-a-view-from-another-controllerOne guy there responded and said that, for my case, it is possible to do things like below:return View("~/Views/Controller1/View1.aspx");But, please let me know if this is considered an acceptable MVC practice.  Is it OK, good, perfect to do so in the asp.net MVC realm?  Thanks, please share your two cents.

General Controller to View logic question

Hello, I am currently learning the MVC2 Framework and I have a brief question in terms of my logic and if their are any flaws in it. I created a basic example in a couple of minutes that demonstrates the way I think about it. public ViewResult Index() { return View(); } public ViewResult Cookies() { return View(new Cookie()); } public ViewResult CookiesInput(Cookie cookie) { return View(cookie); }<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>I really like cookies</h2> Would you like a cookie? <% using (Html.BeginForm("Cookies", "Example")) { %> <p><input type="submit" value="Yes" /></p> <% } %> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Cookies</h2> <% using (Html.BeginForm("CookiesInput", "Example")) { %> <%= Html.EditorForModel() %> <p><input type="submit" value="Gimme" /></p> <% } %> </asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="MainConten

Passing objects between View and Controller

 I would like to pass List<SelectListItem> (not selected item but the whole "List" object) back to controller.for example in my GET controller i would have thisViewData["list"] = some select list from repository;then on post I would like to get the list back from view..pretty much i'm trying to use ViewData["list"] as storage..this way I would use ajax to remove or add items to/from the list.what's the best approach ?thanks

How to retrieve url from another view of controller by code


Dear all

I want to know url of View from another controller.  The following is structure







Now, I want to goto Index view of controller Home from view Login of controller Account

I know  I can use method this.RediectToAction("Index", "Home") to do it but I don't want to method.  It will fail to redirect when view or controller renamed.

Please help



Dear All,

I have

- controller (customer)

public class customer{

public string Name { get; set; }

public string sex {get;set;}


- model (customermodel)

public class customermodel{

public string Name { get; set; }

public string sex {get;set;}


- view (index.aspx)

so i want to transfers presentation model to view (use IList and IEnumberable), how can i do? after i want to display data from database, how can i do ?



problem when passing data from view back to controller?


I have following situation - I am pasing user info object from Controller to View. It contains GUID UserID,  which i dont want to be seen on page.

So I  removed every   Html.LabelFor(model => model.UserID), Html.TextBoxFor(model => model.UserID) etc... from generated View source.

And because of this when Html.BeginForm() returns that object back to Controller  all values is there but UserID is lost??

If I leave Html.LabelFor(model => model.UserID), Html.TextBoxFor(model => model.UserID) etc.. in View everything is fine.

But I dont want to show UserID?

Where is the problem here?

                <%= Html.LabelFor(model => model.C__User_Id) %>

data lost in transition from view->controller


MVC basics or looks like I am doing something terribly wrong, but have not slightly idea what is it?

Want to delete user from MVC Framework's Built in Security Module.

So first I define Delete() in AccountController:

        public ActionResult DeleteUser()


            User_Repository urp = new User_Repository();

            aspnet_Users currUser = urp.Get_AspNet_User(HttpContext.User.Identity.Name);

            return View(currUser);


and this works fine.


I added view (for delete) DeleteUser.aspx


<h3>Are you sure you want to delete this?</h3>




        <div class="display-label">UserId</div>

        <div class="display-field"><%= Html.Encode(Model.UserId) %></div>


        <div class="display-label">UserName</div>

        <div class="display-field"><%= Html.Encode(Model.UserName) %>&

How to Pass data(not the part of model) from View to Controller?


How Can I Pass data(not the part of model) to Controller from View?
View Code

<%= Html.ActionLink(item.Name, "ActionName", "ControllerName", new { companyID = Html.Encode("abc"), ID = Html.Encode("xyz") })%>

Controller Code

public ActionResult ActionName(string companyID , string ID)

Any idea?

Problem adding a View to a Controller in VS 2010 Express


Hi all,

I am very new to ASP.Net Forums and just starting up with MVC2.

For that, I was trying to build MVCMusicStore Application based upon the guidelines from ASP.Net site.

But when I am trying to add a view from controller or from Solution Explorer. VS stops responding.

I am using Windows 7 Enterprise as an OS and Microsoft Visual Web Developer 2010

Is it a problem related to installation or something else???

Please help me out... :(

Invalid Password message on View From COntroller


If the password is invalid, how can I show "Invalid Password"on view ?

   <% Html.EnableClientValidation(); %>
   <% using (Html.BeginForm("Submit", "MyController", FormMethod.Post))
   <%= Html.ValidationSummary(true) %>
   <div><b><%= Html.LabelFor(x => x.UserModel.Password)%>:  </b><%= Html.PasswordFor(x => x.UserModel.Password)%>
   <%= Html.ValidationMessageFor(x => x.UserModel.Password)%>
    <input type="submit" name="submitButton" value="Accept"   />
    <% } %>


 bool isAuthenticate = IsAuthenticate(...);
    if (!isAuthenticate)
        return View("MyPasswordView", UserModel);



Deleting a Controller Action and its View in one step


Since a Controller Action and its View are associated with each other I would think that there would be a way to delete both in one step.

Is that possible? 

add/delete row & colom in Gird View using java script


 Dear Frs,

I create a gridview with text box and Dropdown control.

so that user can select value from dropdown(populate item from DB) and enter text on text boxx.

I bind this grdview with empty DB on page load.


Now i want that as user hit enter tab on text box a new row create with dropdown and text box.

i want do this only using Java script. because i dont want to go server side for add ing and deleting row.


i tryed this one http://geekswithblogs.net/dotNETvinz/archive/2009/06/04/adding-dynamic-rows-in-gridview-with-textboxes.aspx but not as i want.


I want add /delete row/com of gridview using java script only


Its very urregent dear so please fast reply if some one having solution. please copy/paste a ccomplete code for this

Thanks in advance


Register Java-Script Events on SharePoint 2010 Gantt View



did someone of you already try to implement dragging and dropping items in Gantt View for SharePoint 2010?

I was trying to register some JavaScript-Events on the vml-Elements (<v:shape class="jsgrid-vml".../>) representing events in the gantt-view. The problem is that i can not access theese items through DOM... Theese Elements are also not included in the html-code of the page (right click-> view source)...

Before I start to write a SilverLight-WebPart I just wanted to ask, if there are better Ideas...:-)



Register a script block to page without added to view source


Hi Experts,

I want to know do is there any way to register a script block to web page without the script code is added to view source?


Model View Controller - MVC Framework

This article furnishes the information about the Model View Controller (MVC) and the overview of Asp.Net MVC framework . All the basic information about MVC is covered in this article.

Passing data from Controller to View in ASP.NET MVC

ASP.NET MVC is a framework that facilitates building web applications based on MVC (Model-View-Controller) design pattern.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend