Dynamic button create in the mvc view - c#

I have some code clarification. I have a project that in MVC. When view loaded in the web application and then need to be create input button dynamically in the view page. And also how they merge in the controller. I don't have any idea about this I checked many webs but does not have any answer for this.
How to create button dynamically when view load in the web?

If you want to create button after the page loads then you have to use javascript to create the html and then add that to the page.
For example:
$(document).append(
$("input")
.attr("type", "button")
.click(function(){
doSomething()
))
);
You can find the detail of the answer here: Inject html using Javascript

Related

How can I add items in the view, but sequentially

I have a page with for example personal data, I want to have a Go button for other items such as job data but on the same current page with a Go button (next) and so on...
What is this characteristic called Please provide a link to it, or a brief explanation. (like multiview in old version 'asp.net web form')
I'm using asp.net core
This problem could be solve by using ajax.
In your controller you have to make a action just like this
public JsonResult GetYourData()
{
//Add your data here. Make a string along with your data like '<h2>Job Data</h2><p>Title:Software-Developer</p>'
return Json(yourCreatedString, JsonRequestBehavior.AllowGet);
}
Now in view you could add an event on the button click, ask for this above action, get the html in string format, and append that to your DOM

How can I pass data from a form in an ASPX page to a MVC controller?

Hi have a legacy application using ASPX, I have been adding new features to it using MVC.
I'm in a situation where I have a form in the original ASPX pages and I need to do some extra work with the data provided by it. I want to send this data to a MVC controller and do the extra work there and return the results to the user with the MVC side of the application.
The ASPX pages have a SiteMaster that has a form over the entire body. The form has runat="server" set. From my limited knowledge of ASPX, I understand that I can't simply wrap the form in my own form Tag and set the action to the MVC controller. To pass the the form data I need to use a C# function that is called on click.
I have tried Response.Redirect and Server.Target but I can't figure out how to sent the form data using either of these methods.
In summary I need to send data from an ASPX form to an MVC Controller.
You can set the action of the form tag in webforms, e.g.
<form id="Form1" runat="server" action="/Controller/Action" >
and post whatever form data you need to your actions [HttpPost]

Tying it all together - ASP.NET with Bootstrap 3.0

I have an ASP.NET project (non-MVC) and I'm also using Bootstrap 3.0. This is my first time using this combination and need some guidance.
I have a gridview with a buttonfield column. Right now everything is showing up just fine with my gird and Bootstrap table formatting and its binding to my datatable - no problems there.
Next, I want to make the click of the button in the Buttonfield column to initiate a modal window and display a modal based on a unique ID from the row button that opened it.
I don't really know how to tie this all together with ASP.NET and Bootstrap. HTML literals? Dynamic ASP.NET panels? It doesn't matter to me whether there is a postback or not, I'd really just like some guidance or even pseudo-code on how these can be tied together.
Since the OP specifically requested bootstrap help...
You should go through the bootstrap documentation for modals http://getbootstrap.com/javascript/#modals
It makes no difference if you are using MVC or not and you should not need to do any kind of post back to display the modal.
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" />
Will trigger element with id myModal to be shown.
Using bootstrap's own demo code in this jsfiddle demonstrates opening and dismissing the modal.
For the second part of the question, this updated jsfiddle shows how you can also use the button click event to set a value in the modal. You could do other actions in that event handler like get or send data to the backend or change other elements in the modal.
For your case, you would want to handle all button clicks in a single event handler but you can store the id in a custom attribute on the button element. I like to use custom attributes instead of parsing from name, id, or class attributes. This is the bootstrap convention.
$(function() {
$('button.btn').on('click', function() {
var value = $(this).attr('data-value')
$('div.modal').find('#target').text(value);
});
});
Here I have broken out how to get the custom attribute value from the button instance which was clicked.
Post what you have so far and what you still can't get working.
This also shouldn't be tagged with C# or asp.net as that is irrelevant.
You might need a simple js function to take care of that(as mike mentioned this has nothing to do with using or not using bootstrap since it is just some css stuff):
var RunDialog;
$(document).ready(function () {
RunDialog = $("#Id").dialog();
});
You can use ASP.Net Ajax ModalPopup for ASP.Net Web Form. You can google a lot of examples regarding GridView with ModelPopup.
ModalPopupExtender inside a GridView ItemTemplate
I want to make the click of the button in the Buttonfield column to
initiate a modal window and display a modal based on a unique ID from
the row button that opened it.
ModalPopup should work with Bootstrap.

ASP.net Passing Links from Page to Page

I am trying to display a page into an IFrame.
The IFrame is displayed into a fancyBox overlay popup.
I have a list with the http links (gets compiled at runtime and it constantly changes).
Using a global variable I can access the list with the links.
But the http link in the list must match the link I have clicked.
If I can even get the link which I have clicked it will also be enough (the link brings up a fancyBox popup so it doesn't actually bring up a new page so to speak)
How to do that?
You have to write some tricky code to achieve this, main goal is to edit the dynamically added page content by adding wrapper tag (with onclick event) around all the links, writing javascript to be called using that wrapper to findout which link has been clicked,
You can try this by doing following steps
1) Get the content of IFrame , using the following JQuery code you can get the content of IFrame
var $currentIFrame = $('#myIFrame');
var content = $currentIFrame.contents();
2) Now manupulate these content by finding all the links inside that page and wrapping them with a tag that should have onclick event e.g. span , you have to write some javascript function to fire on a link if user clicks it.
see the following link for how to manipulate content
Get all links inside iframe and add blank target attribute

return PartialView to a popup windows at another view

I have an Index.aspx with a button inside which that button will call a controller, doing some logic and returning to a PartialView control - let's named it PopUpPartialView.ascx (as a popup). So to make it clear, the popup windows(PopUpPartialView) actually stays ON the top of Index.aspx when user clicks on the button.
In PopUpPartialView.ascx, there is another button, that returns say a GenerateList and now the problem is - how do I pass the thing back to the same popup windows in PopUpPartialView.ascx on the top of Index.aspx as it was before? How should my controller codes look like?
Here's what I have on the return:
return PartialView("PopUpPartialView", GenerateList);
this clearly NOT working as what I want, because it doesn't point back to Index page. I was thinking perhaps to use ajax so that I could stay on that popup ascx page. Confused~~ Someone please guide me.
Thanks.
My advice is to use a plugin which handles all the popup plumbing for you.
My poison of choice is jqModal.
It's very easy to work with - essentially a hidden container on the page, and you can load contents in there either on the initial render, or on a click event via AJAX.
So in your example, you could handle the button event click, show the dialog and load the contents of your partial view into the hidden container.

Categories