We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Using components in razor view

Thread ID:

Created:

Updated:

Platform:

Replies:

130920 Jun 11,2017 11:42 AM UTC Jun 12,2017 11:44 AM UTC JavaScript 1
loading
Tags: ejAutoCompleteTextBox
Tolga
Asked On June 11, 2017 11:42 AM UTC

Hi

Is it possible to use jscript components within asp.net forms which is written with razor engine?

Lets assume I have a form which is created by razor tag helpers and there is field called user id which needs to be implemented as autocompleteTextBox.

Can I get the value from ejAutoCompleteTextbox (js) and set the selected value to asp.net form field?

Or this hybrid approach is bad idea?





Arun Palaniyandi [Syncfusion]
Replied On June 12, 2017 11:44 AM UTC

Hi Tolga, 

 

Thanks for contacting Syncfusion support.   


Is it possible to use jscript components within asp.net forms which is written with razor engine? 
 

Yes, you can use the JavaScript components within asp.net forms which is written with razor engine.  

 

Lets assume I have a form which is created by razor tag helpers and there is field called user id which needs to be implemented as autocompleteTextBox. 

 

Yes, you can implement our Autocomplete using both JavaScript and as html razor tag helpers. Our component will be rendered both ways in the razor page.   

 

 

<div class="form-group"> 

            @Html.LabelFor(model => model.Userid, htmlAttributes: new { @class = "control-label col-md-2" }) 

            <div class="col-md-10"> 

               <h4>ejAutoCompleteTextbox as html razor MVC components</h4> 

                @{ Html.EJ().Autocomplete("Userid").Width("100%").Datasource((IEnumerable<MvcApplication33.Models.AutocompelteDetails>)ViewBag.datasource).WatermarkText("Select a Userid").AutocompleteFields(af => af.Text("Userid")).Render();} 

                @Html.ValidationMessageFor(model => model.Userid, "", new { @class = "text-danger" }) 

            </div> 

        </div> 

 

        <div class="form-group"> 

            @Html.LabelFor(model => model.Address, htmlAttributes: new { @class = "control-label col-md-2" }) 

            <div class="col-md-10"> 

                <h4>ejAutoCompleteTextbox as jscript components</h4> 

                <input type="text" id="Address" /> 

                @Html.ValidationMessageFor(model => model.Address, "", new { @class = "text-danger" }) 

            </div> 

        </div> 

 

<script> 

 

    $(function () { 

 

        $('#Address').ejAutocomplete({ 

            dataSource: states, 

            fields: { key: "index", text: "countryName" }, 

            watermarkText: "Select a Address", 

            width: "100%" 

        

        }); 

    }); 

 

 

</script> 

 

 

Can I get the value from ejAutoCompleteTextbox (js) and set the selected value to asp.net form field? 
 

Yes, you can get the values from both JavaScript and html razor syntax Autocomplete component in the controller. 

 
 
  
 
 
 
 
 

Or this hybrid approach is bad idea? 
 

No, it is not a bad idea to render our Autocomplete control as JavaScript control within asp.net forms with razor engine.   



We have also prepared a sample for your reference below:   

 

http://www.syncfusion.com/downloads/support/forum/130920/ze/AutocompleteForms760525046 

 

 

If the shared details and sample doesn’t meet your requirement, please give us more information to provide an alternative solution.    

    

Regards,
Arun P.    

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;