.NET MVC

394

Solutions

294

Contributors

Microsoft’s ASP.NET MVC is a web application framework that implements the model–view–controller (MVC) pattern. As an open-source software, it’s set apart from the ASP.NET Web Forms component, which is proprietary.

Share tech news, updates, or what's on your mind.

Sign up to Post

The following codes came from mvc action result.
Assume the message return string called "file 1"
Using javascript, how to get value (which is file 1).

Thanks

 if (isSavedSuccessfully)
            {
                return Json(new { Message = fName });
            }

Open in new window

0
Fundamentals of JavaScript
LVL 19
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Hi,

my Group select is not triggering my on change event.

1. I have a select dropdown list that select px or dx .....
2. Upon selecting from the first dropdown list the Group select will get populated with a list of dx or px.....
3. ounce the user select from the list of dx or px I need to populate the textarea with the list Item.
but for some reason my Group Select is not triggering my on change event to send the data to the textarea called ItemsTextArea

<script>
    $(document).ready(function () {

       // debugger;

        $('#OperatorSelect').multiselect(getOperatorOptions(true));
        $('#ConditionSelect').multiselect(getOperatorOptions(true));
        $('#ValueSelect').multiselect(getOperatorOptions(true));
        $('#GroupSelect').multiselect(getGroupOptions(true));


        $("#ConditionSelect").change(function (event) {
            var GetValue = $(this).val();
            $('#HiddenFieldForSelectedCondition').val(GetValue);
            var method = $('#RulePartialViewForm').attr("method").toLowerCase();
            var action = $('#RulePartialViewForm').attr("action");
            var data = $('#RulePartialViewForm').serialize();
            $.ajax({ method: method, url: action, data: data }).done(
                function (json) {
                    var arr = [ '<option>Select</option>' ];
                    $.each(json, function (i, obj) {
                        arr.push('<option value="' + json[i].Value + '">' + json[i].Text

Open in new window

0
Hi Experts,
I want to convert this simple query to a LINQ query in C#.
select distinct c.MemberID,max(c.approved)  from Claims c
join member m on c.MemberID = m.MemberId
where m.Id = 910318 and  c.PointsEarned > 0 group by c.MemberID

Open in new window

Any help is appriciated!
Thanks in advance.
0
Hi,

How can I send back my model info to the dialog box ounce I submitted its form.
right now it's asking me to save json file after my submission

         [HttpPost]
        public JsonResult RulePartialView(CABRRulePartialViewModel model)
        {
            model.SelectGroupDataListSource = _careAdvanceBusinessRulessService.GetGroupse();
            model.SelectGroupDataSource = _careAdvanceBusinessRulessService.SelectedDataFromGroup(model.HiddenFieldForSelectedCondition);

            Thread.Sleep(1000);
            return Json(model, JsonRequestBehavior.AllowGet);
}

Open in new window



my dialog box partial view


@model BCUW.Model.CABusinessRules.CABRRulePartialViewModel




<script >
    $(document).ready(function () {

        debugger;

        $('#OperatorSelect').multiselect(getOperatorOptions(true));
        $('#ConditionSelect').multiselect(getOperatorOptions(true));
        $('#ValueSelect').multiselect(getOperatorOptions(true));
        $('#GroupSelect').multiselect(getGroupOptions(true));

        
        $("#ConditionSelect").change(function () {
            var GetValue = $(this).val();
            $('#HiddenFieldForSelectedCondition').val(GetValue);
            
            $('#RulePartialViewForm').submit();
        });


        function getOperatorOptions(isFilter) {
            return {
                buttonWidth: '170px'
            }
        }


        function getGroupOptions(isFilter) {
            return {
                

Open in new window

0
Hi,

my dialog box has the word "close" on top right
 
how can I remove it?

Thanks,


  $(function () {
            $('#dialog').dialog({
                autoOpen: false,
                width: 800,
                height:600,
                resizable: true,
                title: 'Product',
                modal: true,
                open: function(event, ui) {
                    $(this).load("@Url.Action("RulePartialView", "CareAdvanceBusinessRules")");
                },
                buttons: {
                    "Close": function () {
                        $(this).dialog("close");
                    }
                }

            });
            $("#opener").click(function (event) {
                event.preventDefault(); 
                $("#dialog").dialog("open");
            });
        });

  <div id="dialog" title="Basic dialog"> </div>

    <a id="opener" href="@Url.Action("RulePartialView", "CareAdvanceBusinessRules")">Click to open popup window </a>

Open in new window

0
Hi,
When I click on my link, it takes me to a whole new page instead of opening my partial view page in a popup window.
I’m not sure what I’m doing wrong can you please take a look and let me know
Thanks,


Controller: 
      public ActionResult RulePartialView()
        {
            CABRRulePartialViewModel model = new CABRRulePartialViewModel();

            return PartialView(model);
        }

Open in new window


Index page: 

    $(document).ready(function () {
$(function () {
            $('#dialog').dialog({
                autoOpen: false,
                width: 400,
                height:500,
                resizable: false,
                title: 'Product',
                modal: true,
                open: function(event, ui) {
                    $(this).load("@Url.Action("RulePartialView", "CareAdvanceBusinessRules")");
                },
                buttons: {
                    "Close": function () {
                        $(this).dialog("close");
                    }
                }
            });
            $("#opener").click(function () {
                $("#dialog").dialog("open");
            });
        });

  });


    <div id="dialog" title="Basic dialog"> </div>

    <a id="opener" href="@Url.Action("RulePartialView", "CareAdvanceBusinessRules")">Click to open popup window </a>

Open in new window


Partial view page 

@model BCUW.Model.CABusinessRules.CABRRulePartialViewModel

<p>hello this is the partial view page</p>

Open in new window

0
In my MVC project I created a tab called "Knowledge". I was finally able to make some things work. I implemented a YADCF datatable on it but it is not working. The datatable features appear to be there but not the yadcf. I included the code below and the images of the three errors I get in the console. Please help, thank you!

Here is my code:

       
@model IEnumerable<HelpDeskSupport.Models.KnowledgeBaseModel>

    @{
    Layout = null;
    }

<!DOCTYPE html>

<head>
    
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/yadcf-master/jquery.dataTables.yadcf.css"></script>
    <script src="~/yadcf-master/jquery.dataTables.yadcf.js"></script>
    <script src="~/DataTables/datatables.css"></script>
    <script src="~/DataTables/datatables.js"></script>

    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

    </head>
    <table class="display table table-striped table-bordered" id="knowledgeTable">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.KBSubject)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.KBFrom)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.KBAssignedTo)
            </th>
            <th>
                

Open in new window

0
Hello!!!

I have an input form and on that form the user should be able to upload multiple files.  

I have the UI / Jquery uploading multiple files and deleting multiple files working great.

the problem that I have is in my controller, I don't know how to get the files into my model with multiple unlimited files.

Let me show you what I have

//With this code user can upload and remove multiple files: 

    $(document).ready(function () {

        $("#FileCount").val("");

    });




//Begin multiple file upload
    var counter = 0;
    function AddFileUpload()
    {
        var div = document.createElement('DIV');

        div.innerHTML = '<button class="btn btn-default glyphicon glyphicon-remove" style="height:41px; padding: 10px; -webkit-border-radius: 10px; -moz-border-radius: 10px; width:80px;border: 1px solid #BBB;cursor:pointer;" id="Button' + counter + '" type="button" ' +
          'value="Remove" onclick = "RemoveFileUpload(this)" >' +
          '</button>'  +

        '<input id="file' + counter + '" name = "file' + counter +
        '" type="file" class="fileStyle" />';

        document.getElementById("FileUploadContainer").appendChild(div);

        counter++;

        $('#FileCount').val(counter);

    }


    function RemoveFileUpload(div)
    {
        var el = document.getElementById("FileUploadContainer");
        el.removeChild(div.parentNode);
        var children = el.getElementsByTagName('input');
        counter = 0;
        for 

Open in new window

0
Hi Experts,
 @Html.FacetDropDownList("ID", Model.ID, new { @class = "special-dropdown", title = T("Select a student").Text })

Open in new window


Is there anyway I can access this title in jquery?

Thanks in advance!
0
Hi Guys!!!

I'm new to MVC C# coding and I really need your help.

I have a left menu that I want to be populated from my database and I'm not sure how to do it.

Thank you in advance for taking the time to help me with this.

I have two tables a parent table and a child table 

Parent table called: RuleSet

RuleSetID       |     RuleSet                 |    CreatedDate   |     CreatedBy 
1                             Blended                      11/12/2019            Y000001
2                             OSCMain                     11/12/2019            Y000001
3                             Questionnaire            11/12/2019            Y000001

Child table called: RuleIdentifier

RuleIdentifierId    |    RuleSetId    |    RuleIdentifier            |      CreatedDate   |    CreatedBy
1                                     1                       Blended_00010                 11/12/2019            Y000001
2                                     2                       OSCMain_0049                  11/12/2019           Y000001
3                                     2                       OSCMain_0010                  11/12/2019           Y000001
4                                     2                       OSCMain_0122                  11/12/2019           Y000001
5                                     1                       Blended_0234                    11/12/2019           Y000001
6                                     3                       Questionnaire_02 

Open in new window

0
Acronis in Gartner 2019 MQ for datacenter backup
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Hi Experts,

This is my view model.

public class ResellerHomePageViewModel {
        public IList<SelectListItem> SelectList { get; set; }
    }

Open in new window


I have a dropdown list called "SelectPartner"
<select id="SelectPartner">
<option id="defaultOption" value=""></option>

</select>

Open in new window


How can I bind the value of "SelectList " (Model. SelectList ) to the dropdown list "SelectPartner" using jQuery on document.ready function?

Thanks in advance.
0
How can I make my text area editor disabled if the user typed in more than 4000 characters?

I have tried the disable syntax but it's not working


<link type="text/css" rel="stylesheet" href="~/Content/CWScss/jodit.min.css">
<script type="text/javascript" src="~/Scripts/jodit.min.js"></script>


 jQuery(function () {
            var maxLength4000 = 4000;
            $(document).on("keyup paste blur click touchend", function () {
                var textlen = maxLength4000 - $("#AttributesAndValue").val().length;

                 //Here I want to say if textlen more than 4000 char then disable my text editor 
                //my disable is not working 

                if ($("#AttributesAndValue").text().length == 4000 || textlen <= -1) {
                    $('#AttributesAndValue').prop("disabled", true);
                }


                $('#rchars').text(textlen);
            });
            $('#AttributesAndValue').each(function () {
                var AttributesAndValue = new Jodit(this);
                AttributesAndValue.setDisabled();
            });
        });


                  <div class="form-group purple-border">
                        Attribute(s) and Value(s)
                        @Html.TextArea("AttributesAndValue", new { @class = "form-control", @style = "width:77%" })
                          <div id="ValidateAttributesAndValue" style="color:#bc0606;font-weight:bold;">Required Field</div>
                        <span 

Open in new window

0
Count HTML text area characters not to exceed 4000.  

I'm not able to display the total count of characters.

<link type="text/css" rel="stylesheet" href="~/Content/CWScss/jodit.min.css">
<script type="text/javascript" src="~/Scripts/jodit.min.js"></script>

 $('#AttributesAndValue').each(function () {
            var AttributesAndValue = new Jodit(this);
            //editor.value = '<p>start</p>';
        });

        var maxLength4000 = 4000;
        $('#AttributesAndValue').keyup(function () {
            // var textlen = maxLength4000 - $(this).val().length;
            $('#rchars').text(textlen);
        });


                   <div class="form-group purple-border">
                        Attribute(s) and Value(s)
                        @Html.TextArea("AttributesAndValue", new { @class = "form-control", @style = "width:77%" })
                         <span id="rchars">4000</span> Character(s) Remaining
                        <div id="ValidateAttributesAndValue" style="color:#bc0606;font-weight:bold;">Required Field</div>
                    </div>

Open in new window


Thanks,
Lulu50
0
Does Entity Framework sometimes auto-convert DateTime to EST?

My Javascript call is making an MVC call to a C# web method with a date that is set to midnight. But, when I query the database, I see the correct date was added to the DB table, as expected. However,  there is time added, and it turns out to be UTC time:

I am on the East Cost of the US and am currently 4 hours behind UTC/GMT.

Here is the format of the data:

2019-11-01 04:00:00.000

I was expecting:
2019-11-01 00:00:00.000

Since, the JSON date/time I am passing in was at midnight.

Is there a setting in Entity Framework which may cause this?

Or, is there a JSON parser doing this?


Thanks
0
Hi,

I have to add a text editor to my project and I wonder if you anyone know where I can download an example.

The user should be able to bold and change the color of the text. so that's why I need to add a text editor to my project.  

Thanks,
lulu
0
Can you please tell me why this routine is not showing values in the text box when i click in the text area?
screenshot.JPG
      private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox i = sender as ListBox;
            if (i.SelectedIndex != -1)
            {
                listBox1.SelectedIndex = i.SelectedIndex;
                listBox2.SelectedIndex = i.SelectedIndex;
                txtID.Text = listBox1.SelectedItem.ToString();
                txtName.Text = listBox2.SelectedItem.ToString();               
            }
        
        }

Open in new window

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace InsertUpdateDel
{
    public partial class Form1 : Form
    {
        SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Lenovo\Documents\Visual Studio 2012\Projects\InsertUpdateDel\InsertUpdateDel\Database1.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand();
        SqlDataReader sd;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                cmd.Connection = cn;
                loadlist();
        }

        private void button1_Click(object sender, 

Open in new window

0
Can you please help me in that error?
screenshot.JPG
namespace InsertUpdateDel
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.txtID = new System.Windows.Forms.TextBox();
            this.txtName = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.listBox2 = new System.Windows.Forms.ListBox();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            

Open in new window

0
I have a Asp.Net Core Application.

On one of my views I have an anchor tag like this this.

<a asp-controller="Speaker"
   asp-action="Index">All Speakers</a>

i have a CSS class that looks like this:

.LinkStyle1 a:link { color: #0000FF; }

Is there a way to add this class style to the asp-controller link tag?

One way that works is like this:

<span class=“LinkStyle1”><a asp-controller="Speaker"
   asp-action="Index">All Speakers</a></span>

Is there a better way to apply a css class to this asp-controller tag?
0
I like to know is there any dll for edit image for website. purpose is to edit image & add text & mark circles on image before save.
0
Success in ‘20 With a Profitable Pricing Strategy
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

I have buttons using URL.Action and cannot get them to open in a new tab.  I've tried target=_blank with no luck!

 <button class="btn btn-info" style ="width:90px;" onclick="location.href='@Url.Action("LocationDetails", "Location", new
                                                                                                                 { id = @Model.id                                                                                                 
                                                                                                                 }
                                                                                         
                                )'">
                                Details
                            </button>

Open in new window

0
I have the following json string. how  to read it in c# FOR  LOOP?

{Employee:[{"principalfirstname":"xxx","principallastname":"xxx","principalmiddlename":"xxx","principalnameonbond":"xxx","principaldba":"xxx","principalentity":"USA","principalyearinbusiness":"xxx","principaltaxid":"","principaladdress":"xx","principalcity":"xxx","principalstate":"TN","principalzip":"111","principalcounty":"","principalphoneno":"xxx","principalemail":"","principalfaxno":"","vin":"","licenseplatenumber":"","driverlicensenumber":"","door":"","bondstate":"","bondamount":"","premium":"","bondterm":"","creditcardfullname":"","creditcardnumber":"55555555533331111","creditcardchargeamount":"","creditcardexpdatemm":"","creditcardexpdateyyyy":"","creditcardcvc":"","creditcardaddress":"","creditcardcity":"","creditcardstate":"","creditcardzip":""}]}

Open in new window

0
Hello Experts,

I'm new to MVC and JQuery web development. I'm trying to bind the data to my datatable using JSon object. Below is the sample code:

View
<div id="mdlMsg" class="modal fade" tabindex="-1" role="dialog">
            <div class="table-responsive m-t-40">
                <table id="dtData" class="display nowrap table  dataTable" cellspacing="0" width="100%">
                    <thead>
                        <tr>
                            <th>Col1</th>
                            <th>Col2</th>
                        </tr>
                    </thead>
                    <tbody id="tblbody"></tbody>
                </table>
            </div>
        </div>

Open in new window


Controller
public async Task<ActionResult> Test()
{
 string resp = "";
  var msg = new Dictionary<int, string>();
msg .Add(1, 'Row 1');               
msg .Add(2, 'Row 2');       
      resp= Newtonsoft.Json.JsonConvert.SerializeObject(msg, Newtonsoft.Json.Formatting.Indented);
return resp;
}

Open in new window


Javascript
$.ajax({
        type: 'post',
        url: url,
        processData: false,
        contentType: false,
        data: files,
        success: function (resp) {
 $('#mdlMsg').modal({ show: true })
                var jsonTst = $.parseJSON(resp);
                $('#dtData').dataTable({
                    "bAutoWidth": false,
                    "aaData": jsonTst.data,   //this is your JSON object, which is what is showing in your post above with console.log(data)
                    "aoColumns": [{
                        "jsonTst": "Col1"
                    }, {
                            "jsonTst": "Col2"
                    }]
                });
});

Open in new window


The modal popup shows with no data and also I want to fix my Modal popup to be middle of the page.

Thanks,
ASPDEV
0
I have the following ajax codes, and want to send Json data to MVC Controller.
Can you show me how to do that  on MVC Controller?
Thanks

function Submit(domain) {
    //alert("Thank You");
    var x = $('#formdiv *').serializeArray();      
    var data = {};
   $.each(x, function (i, field) {
        data[field.name] = field.value;
   });
    var json = JSON.stringify(data);   
    alert(json);
    $(document).ready(function () {
        $.ajax({
            url: domain + "/Api/ReceiveJson",
            type: "POST",
            data: {json},
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            success: function (data) {alert('Success');},
            error: function (msg) { alert(msg); }
        });
    });
    return false;
}

Open in new window

0
If I have just a simple web form in html and  a submit button., and I want to create json file basically,
when the button is clicked, capture, each id inside of the form in a loop. (My web form will be huge so I do not want to capture one by one).
then create json format, and  drop into root directory like www.hello.com\json\abc.json.

Is it possible?

In my web form I only use type=text and <select></select> and the id name will be header name  inside of json. Just keep it simple. and I do not use <form></form> just <a onclick=submitnow()>

Thanks,

<div class="col-md-6">
    <div class="form-group bd-t-0-force">
        <label class="form-control-label"><i class="fa fa-credit-card"></i> Card Number: <span class="tx-danger">*</span></label>
        <input class="form-control" type="text" name="ccnumber" value="Market St., San Francisco" placeholder="Enter Card No.">
    </div>
</div><!-- col-8 -->
<div class="col-md-2">
    <div class="form-group mg-md-l--1 bd-t-0-force">
        <label class="form-control-label"><i class="fa fa-credit-card"></i> Card Expiration Month: <span class="tx-danger">*</span></label>
        <input class="form-control" type="text" name="ccexpdatemm" value="" placeholder="Enter Card Expiration Date Month">
    </div>
</div><!-- col-4 -->
<div class="col-md-2">
    <div class="form-group mg-md-l--1 bd-t-0-force">
        <label class="form-control-label"><i class="fa fa-credit-card"></i> Card Expiration Year: <span 

Open in new window

0
Hello Experts,

I'm new to MVC devlopment, I was using Viewbag to pass the data from my controller to JS(jquery function). I want to know how can I read the List data and then assign to my grid. This is the sample code, I was getting error while reading the ViewBag.MyList in my JS function. How can I do this so I can get the list object. Later part once I get the list object, then I will bind the data with the grid.

Controller
public async Task<ActionResult> TestData(
string resp = "";
 var test = new List<Tuple<int, string>>();
test.Add(new Tuple<int, string>(1, 'R1'));
test.Add(new Tuple<int, string>(2, 'R2'));

if (test.Count > 0) {
ViewBag.MyList= Newtonsoft.Json.JsonConvert.SerializeObject(test);
}

resp = "test";
}

Open in new window


JavaScript
$.ajax({
        type: 'post',
        url: url,
        processData: false,
        contentType: false,
        data: files,
        success: function (response) {

 if (response == 'test')
{
var testList= JSON.parse('@Html.Raw(ViewBag.MyList)');
}
}

Open in new window

0

.NET MVC

394

Solutions

294

Contributors

Microsoft’s ASP.NET MVC is a web application framework that implements the model–view–controller (MVC) pattern. As an open-source software, it’s set apart from the ASP.NET Web Forms component, which is proprietary.

Top Experts In
.NET MVC
<
Monthly
>