Is it possible to pass values from a Razor component to a Razor page? - model-view-controller

I'm integrating Razor components into ASP.NET Core Razor Pages in my Blazor Webassembly project in order to keep the UI consistent between the client and server.
One of these components is a multiselect dropdown and I'm having a really hard time getting the model of my Razor page to bind to the values in my component.
Is there another way I can pass data from my component to the page? I know it's easy to pass data the other way via parameters, but I'm struggling to work out how to do it the other way around.

Related

Ajax connected webparts in sharepoint 2013

I need to implement custom treeview with categories and connect this webpart with ListView webpart. Can this be done with ajax? How? And how to pass param from provider via JS (I know only __doPostBack method, are there any other ways)?
I think your best bet is to look at the JavaScript API for SharePoint:
API Reference
And then integrate code that queries your views in a list with the jsTree jQuery plugin:
jsTree Reference
Now you can use JQuery to determine what's happening with your list view web part, but it will be time consuming. I would use the Microsoft Javascript API to create a drop down of the various views you have in your list, and then render that data in such a way it will work with the markup jsTree requires.

Is it possible to render body with ajax in asp .net mvc project with layout?

Is it possible to render body with ajax in asp .net mvc project with layout?
Yes, it is possible, but it doesn't make any sense as it will result in a completely broken and invalid markup. You will end up with a 2 headed and 2 body beast like Quazimodo. Actions that are requested view AJAX normally should return only partial views, not full views with layout. Or if you if you belong to some bandwidth saving party you could have your actions return JSON and then use a client side templating framework in order to lay out the markup.
RenderBody is used on page postbacks to render a new HTML document with data from the server that has been annotated with the Razor templating engine. AJAX is used to retrieve data from the server asychronously (in a JSON format typically). An AJAX request can be used to retrieve the same data that RenderBody() would, but it wouldn't make much sense and isn't best practice.

Two forms (one in layout and one in Page) how to handle in asp.net mvc3

I am working on a mobile website in ASP.NET MVC3. I have a page where i have search bar in my header. this header is coming from my Layout page which is common to all other Views. And inside my specific page, I have page specific content(forms).
For my Customer/Add action, I return the Add View of Customer which is strongly typed to my CustomerViewModel. I will have form tag in my Add View which will be posted to HttpPost Add Action method when form gets submitted. That is fine. My question is how will i handle the search box content ? I believe only one form is allowed in the page.So if i have a SearchViewModel which is binded to my Search View(Partial), It is going to be 2 forms in my page. So i can not do that.
I can handle the search part by reading the content in java script and calling another action to get Search results.Is that the only way to do that ? I am worried about those devices where java script is disabled. What should i do ? Please advice
No. You can have more than 1 form on the page. In fact, here you should. Your Add Customer page should submit to 1 action method, but your search form should submit to a different action method.
If you are familiar with webforms, that framework only allows you to have 1 form on the page, but not because HTML requires it. Webforms requires it because it is the only way the framework can carry all of the data from various server controls across POST requests (using ViewState). Webforms has historically not been very HTML or HTTP friendly.
You just can't have forms nested within other forms in HTML, but it is completely legal (and recommended in MVC) to have more than 1 form on a page.
As for AJAX, I would not worry about devices that do not have javascript enabled. There are only like 6 or 7 people on the planet that don't have javascript on their web devices, and if someone disables javascript, they won't be able to experience 99% of the rest of the web anyhow.

Asp.net MVC Ajax - Disabling button in ajax.beginform?

I'm using microsoft ajax and ajax.beginform.
It's working great for model binding my partial view, but I need to conditionally disable some of the buttons in my form itself depending on what comes back from the server.
How can I go about this without using JQuery?
Have you thought instead about using two separate views instead, and have your conditional logic in your controller determine which view to display.

MyUpdatePanel.Update() in Razor

I am trying to convert my existing ASP.NET application to MVC 3 Razor. I use a lot of updatepanels, and I do conditional updates at the code behind using MyUpdatePanel.Update().
I am not finding this functionality with MVC 3. I can see a lot of blogposts talking about jQuery and how to use it to achieve the same, but I want to render other partialviews from my action conditionally. Is it possible to achieve it?
The way you'd work with Ajax in ASP.NET MVC is completely different from the ASP.NET way (i.e., Ajax toolkit with server-side controls such as UpdatePanel).
ASP.NET MVC is more basic and therefore more work. You handle Ajax calls on the client side using a library such as jQuery, and on the server side you implement a controller with Ajax methods.
Have a look at http://sweettam.blogspot.com/2011/06/aspnet-mvc-3-ajax-part-i.html.

Resources