Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • hakan 24 posts 118 karma points
    Nov 20, 2018 @ 13:29
    hakan
    0

    how can I send data to view from controller?

    First I sent my data to controller from view.

    @using (Html.BeginUmbracoForm<MyProject.Controllers.searchResultsController>("SearchResults"))
                            {
                                <input type="text" class="inputTypeB cbox04A-01" name="searchText" placeholder="@Umbraco.GetDictionaryValue("Search_v1")" />
                                <button type="submit" class="cbox04A-02">
                                    <img src="~/Content/Images/icon-search-light.png" />
                                </button>
                            }
    

    after I get searchtext from controller and find my result. but I cant send that results to view.

    I use SurfaceController because I cant catch data when I use RenderMvcController.

        public class searchResultsController: SurfaceController
    {       [HttpPost]
        public ActionResult SearchResults(string searchText)
        {
            if (searchText == "")
            {
                return CurrentUmbracoPage();
            }
            List<searchResultModel> searchResult = new List<searchResultModel>();
            foreach (var result in Umbraco.TypedSearch(searchText, useWildCards: true))
            {
                if (result.TemplateId != 0)
                {
                    searchResultModel s = new searchResultModel();
                    s.Name = result.Name;
                    s.Url = result.Url;
                    searchResult.Add(s);
                }
            }   
                return View(searchResult);
        }}
    

    that is my model

    public class searchResultModel
    {
        public string Name { get; set; }
        public string Url { get; set; }
    }
    

    that is SearchResult.cshtml view

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<MyProject.Models.searchResultModel>
    
      @{
                dynamic s = Model;
            }
            @foreach (var item in s)
            {
                <a href="@item.Url" class="textItem">
                    <div class="text01 ff-pr-11">
                        <p><b>@Html.Raw(item.Name)</b></p>
                    </div>
                    <div class="text02 ff-pr-11">
                        <p>@Html.Raw(item.Url)</p>
                    </div>
                </a>
            }
    

    please help me about get data and send data with controller in umbraco

Please Sign in or register to post replies

Write your reply to:

Draft