We help IT Professionals succeed at work.

.NET MVC

427

Solutions

311

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.

I am trying to search a file or files based on a a text in the file name in SharePoint Online Document Library. Our objective is to load around 44000 files in a document library (and it would increase with time) and search for files there.
We have uploaded around 10000 files so far and the search fails giving the following error:
The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator.
This means that the administrator has set the maximum items in a view to a certain value. However, this should not happen as the search result would return at most 1 or 2 files.

We are performing the search using Client Object Model (C#). We tried keyword search that did not do anything but when we used CAML query it worked and we got this error. Is there anyway to perform a search without this error?
0
I am diving into MVC and hit a snag.

In my home controller I am populating a ViewBag. Then I am trying to put that into a drop down list

Home controller:

 
string _connectionString = WebConfigurationManager.ConnectionStrings["xxxxxxx"].ToString();

            using (SqlConnection con = new SqlConnection(_connectionString))
            {
                //
                // Open the SqlConnection.
                //
                con.Open();
                //
                // The following code uses an SqlCommand based on the SqlConnection.
                //

            
                SqlDataAdapter _da = new SqlDataAdapter("Select Name from AspNetRoles", con);
                DataTable _dt = new DataTable();


                _da.Fill(_dt);
                
                ViewBag.RoleList = new SelectList(_dt.AsEnumerable());

                
                con.Close();
                
            }

Open in new window


Index.html :
 
@Html.DropDownList("Name", (IEnumerable<SelectListItem>)ViewBag.RoleList, "Select an application", "Name")

Open in new window



My dropdown populates the correct number of rows, however the proper text does not come up=> system.data.datarow is there 6 times

I am sure I am not converting something....can you help me with this easy newbie question?
0
HttpContext.Current is null after calling ConfigureAwait(false) in ASP.NET MVC using C#.  How do I resolve this problem.?

Please provide code fix.

Many thanks in advance.
0
I have a cache object in C# that still has not expired yet, and I want to update the value of its key. How do I do that? This is for an ASP.NET MVC web app.  For example:

UserLogin userLogin = new UserLogin() {
  LoginAttempts = 1,
  DateTimeAttempted = DateTime.Now
};

if (System.Web.HttpContext.Current.Cache["LoginInfo"] == null)
{
   System.Web.HttpContext.Current.Cache.Insert("LoginInfo", userLogin, null, DateTime.Now.AddSeconds(60), TimeSpan.Zero);
}

if (System.Web.HttpContext.Current.Cache["LoginInfo"] != null && UserAuthenticationFailedAgain)
{
   userLogin.LoginAttempts = 2;
   userLogin.DateTimeAttempted = DateTime.Now;
   // Now how do I update the value of this existing cache object's key "LoginInfo" so that the when I access Cache["LoginInfo"].LoginAttempts and Cache["LoginInfo"]. DateTimeAttempted, I get 2 and an updated date time, respectively??  I don't see System.Web.HttpContext.Current.Cache.Update() in docs.microsoft.com
}


Many thanks in advance.
0
Hi,

I'm getting an error that says " Cannot convert string[] to string " 

My data in the database for the commitID field looks like this:

CommitID 
29384484, 35283847, 44757583
48475739
85757573, 95857374
75757573

Open in new window



...but, my dropdown list has the list as a string[]:

29384484
35283847
44757583
48475739
85757573
95857374
75757573

Open in new window


My dropdown list is on the search page to filter the data but I'm not getting any data right after the commitID code not able to filter the data:

if (model.SelectedCommitID != null)
   list = list.Where(x => x.CommitID.Contains(model.SelectedCommitID));    //I get an error here that says "cannot convert string[] to string"

Open in new window



I tried any() or put the model.SelectedCommitID in a list but it did not work either. These are all my failing trials:

//Filter Commit ID
// if (model.SelectedCommitID != null)
//   {
//     List<string> stringlist = new List<string>();
//   stringlist.Add(model.SelectedCommitID.ToString());
// list = list.Where(x => x.CommitID.Contains(stringlist.ToString()));
// }


//   list = list.Where(x => x.CommitID.Contains(model.SelectedCommitID));   (Did not work)
//list = list.Where(x => x.CommitID.Contains(model.SelectedCommitID.ToString()));     (Did not work) 
//list = list.Where(x => model.SelectedCommitID.Any(m => Equals(x.CommitID.ToString(), m)));     (Did not work)
//list = list.Where(x => x.CommitID.Contains(model.SelectedCommitID.ToString()));    (Did not work)

Open in new window

0
Hi,

I have a dropdown list that list the following data like this. This is the output that I have right now.

<select name="CommitIDListID" class="btn btn-default dropdown-toggle" id="CommitIDListID" multiple="multiple">
    <option value="345456456, 553564646">345456456, 553564646</option>
    <option value="353434534">353434534</option>
    <option value="535443335, 756555666, 755444566">535443335, 756555666, 755444566</option>
    <option value="577543332">577543332</option>
    <option value="755444566">755444566</option>
 </select>

Open in new window


...but I want the output to be like this

<select name="CommitIDListID" class="btn btn-default dropdown-toggle" id="CommitIDListID" multiple="multiple">
    <option value="553564646">553564646</option>
    <option value="345456456">345456456</option>
    <option value="353434534">353434534</option>
    <option value="535443335">535443335</option>
    <option value="577543332">577543332</option>
    <option value="755444566">755444566</option>   // my data will be distinct because I have two records of the same commit ID
    <option value="756555666">756555666</option>
</select>

Open in new window


This is the code that I have right now:

<select multiple="multiple" id="CommitIDListID" name="CommitIDListID" class="btn btn-default dropdown-toggle">
                                @foreach (var data in Model.CommitIDList)
                                {
                                    if (data.Selected)
                                    {
                                        <option value="@data.Value" selected="selected">@data.Text</option>
                                    }
                                    else
                                    {
                                        <option value="@data.Value">@data.Text</option>
                                    }
                                }
                            </select>


  public IEnumerable<SelectListItem> GetAllCommitIDList()
        {
            var GetCommitID = _unitOfWorkCABusinessRules.RuleDetailRepo.GetAll().GroupBy(x => x.CommitID).Select(y => y.First()).Distinct();

            return GetCommitID
                 .Select(x => new SelectListItem
                 {
                     Text = x.CommitID,
                     Value = x.CommitID.ToString(),
                 })
                .Distinct()
                .OrderBy(x => x.Text);

}

Open in new window



This is the code that I'm working on; I know my syntax is wrong:

var CommitIDData = _unitOfWorkCABusinessRules.RuleDetailRepo.GetAll().Select(g => g.CommitID = string.Join(", ", g.CommitID)).Distinct();
         
   return CommitIDData 
                .Select(g => new SelectListItem
                {
                    Text = g.CommitID,
                    Value = g.CommitID.ToString(),
                })
                 .Distinct()
                .OrderBy(g => g.Text);

Open in new window



My table looks like this: table "RuleDetail"

RuleDetailId    Version         Environment     CQTicket        CommitID
16              Version33	    SIT	            ENT19293	    353434534
17              Version22	    SIT	            ENT95837	    345456456, 553564646
18              version 5	    SIT	            ENT8374	        535443335, 756555666, 755444566
19              version 10	    SIT	            ENT89484	    577543332
20              version25	    SIT	            CQ ticket 55	755444566
21              Version11	    SIT	            ENT00222222

Open in new window



Thank you so much for your help,
0
Hi,

my syntax is wrong

I need your help please

  public List<MissedCommitID> MissedCommitIDList(CABRManagement model)
        {
            List<MissedCommitID> MissedCommitIDList = new List<MissedCommitID>();

       
          // Here I want to check if MigrationCommitID  matches CommitID then populate the list MissedCommitIDList 


          // MigrationCommitID and CommitID fields are stored in the model.RuleDetailList
 

          //if both fields do not have the same data then populate the new list. "MissedCommitIDList "



 var MissedCommitID = _unitOfWorkCABusinessRules.RuleDetailRepo.Where(x => x.RuleDetailId == model.RuleDetailList.Where(m => m.RuleDetailID == x.RuleDetailId));

 MissedCommitIDList = MissedCommitIDList.ToList().Select(x => new MissedCommitID
            {
                CQticket = model.RuleDetailList.Select(x => x.CQTicket);
                UserName =
                Version =
                Environment =
                commitID =

               }).ToList();

Open in new window




   public List<RuleDetailMgm> RuleDetailList { get; set; }

        public class RuleDetailMgm
        {
            public int RuleDetailID { get; set; }
            public string CQTicket { get; set; }
            public string Environments { get; set; }
            public string Versions { get; set; }
            public string RuleSet { get; set; }
            public string RuleIdentifier { get; set; }
            public string CommitID { get; set; }

Open in new window

0
Hello everyone,

I need your help please.

How can I have an if statement inside my list
I want to say if the selectedFilterList contain "status" then display the status field on my grid.

I have a dropdown list for the user to select a specific fields to display in my grid.


 modelList = list.ToList().Select(x => new RuleDetail
            {

                if (model.SelectedFilterList.Contains("Status"))  // I need to do the same to all of them if SelectedFilterList contain the string then display it
                {                                                                                 //I have an error here 
                    Status = (Boolean)x.isActive,                            // Can I do an if inside a list? 
                }


                //Status = (Boolean)x.isActive,
                RuleSet = GetRuleset.Where(a => a.RuleSetId == x.RuleSetId).FirstOrDefault().RuleSet,
                RuleIdentifier = GetRuleIdentifier.Where(a => a.RuleIdentifierId == x.RuleIdentifierId).FirstOrDefault().RuleIdentifier,
                Versions = x.Version,
                Environments = x.Environment,
                CommitID = x.CommitID,
                CommitDescription = x.CommitDescription,
              
            }).ToList();

Open in new window

0
Hi,

I'm trying to export my data to an excel document.

this is my first time doing it in MVC C# so I need your help please.

Do I need to create a view document for "ExportToExcel " ?

I'm doing the example that is in this URL:
https://www.yogihosting.com/export-excel-asp-net-mvc/


Thank you for your help ;-)

Filtering the data in my model

    public List<RuleDetail> RuleDetailList(CABRSearchRules model)
        {
            List<RuleDetail> modelList = new List<RuleDetail>();

            IEnumerable<CABR_RuleDetail> list = new List<CABR_RuleDetail>();
            IEnumerable<CABR_HistoryRuleDetail> Historylist = new List<CABR_HistoryRuleDetail>();

            if (model.SelectedCurrentOrHistoryID == 1) //Current
            {
                list = _unitOfWorkCABusinessRules.RuleDetailRepo.GetAll().ToList();

                //Filter Status
                if (model.SelectedStatus != null)
                    list = list.Where(x => x.isActive == model.SelectedStatus);

                //Filter Environment
                if (model.SelectedEnvironment != "All")
                    list = list.Where(x => x.Environment == model.SelectedEnvironment);

                //Filter Version
                if (model.SelectedVersion != null)
                    list = list.Where(x => model.SelectedVersion.Any(m => Equals(x.Version, m)));

                //Filter CQ Ticket
                if (model.SelectedCQticket != null)
                    list = 

Open in new window

0
Hi,

My between date is not working

I'm only getting one record instead of three

I don't know what I'm doing wrong.

I tried without parsing it and that didn't work.

        public DateTime FromCreatedDate { get; set; }
        public DateTime ToCreatedDate { get; set; }

list = list.Where(x => x.CreatedDate >= DateTime.Parse(model.FromCreatedDate.ToString()) && x.CreatedDate <= DateTime.Parse(model.ToCreatedDate.ToString()));

Open in new window

0
Hi,

I'm working with linq and need your help please.

I have a string[] SelectedVersion that I pass from my view to the controller.

I want the linq to return query that contain the string SelectedVersion[]

list = _unitOfWorkCABusinessRules.RuleDetailRepo.GetAll().ToList();

list = list.Where(x => x.Version.Contains(model.SelectedVersion));

model.SelectedVersion is a string array 
x.Version is a string 

Open in new window



the error says: " I cannot convert string [] to string "

how can I solve this syntax?
0
Hi,

How can I show all selected items after the submit?

Can someone help me and tell me what I'm doing wrong please?

Model :


        public IEnumerable<SelectListItem> VersionList { get; set; }

        public List<string> SelectedVersion { get; set; }


      public IEnumerable<SelectListItem> GetVersion()
        {
            var GetVersion = _unitOfWorkCABusinessRules.RuleDetailRepo.GetAll().GroupBy(x => x.Version).Select(y => y.First()).Distinct();

            return GetVersion
                 .Select(x => new SelectListItem
                 {
                     Text = x.Version,
                     Value = x.Version.ToString(),
                 })
                .Distinct()
                .OrderBy(x => x.Text);
        }

Open in new window




controller: 


 [HttpPost]
  public ActionResult SearchRules(CABRSearchRules model, string[] SelectedVersion)
        {

              model.VersionList = _careAdvanceBusinessRulessService.GetVersion();
            model.SelectedVersion = SelectedVersion.ToList();

      return View(model);
        }

Open in new window




        $('#SelectedVersion').multiselect({
            onInitialized: function (option, checked) {
                var values = [];
                var dropdown = $('#SelectedVersion').siblings('.multiselect-container');
                $('#SelectedVersion option').each(function () {
                    values.push($(this).text());
                });
            },
            enableFiltering: true,
            buttonWidth: '350px',
            maxHeight: 200,
            enableCaseInsensitiveFiltering: true,
        }); 



 @Html.DropDownListFor(m => m.SelectedVersion, new SelectList(Model.VersionList, "Value", "Text"), new { @multiple = "multiple" } )

Open in new window

0
Hi,

I'm creating a search page

1. on the page there is a multiselect dropdown list
2. I select some options from the list
3. I click on the submit button
4. after submitting the page my selection will get cleared out

How can I get my selection back once I click on the submit button?


 $('#SelectedVersion').multiselect({
            onInitialized: function (option, checked) {
                var dropdown = $('#SelectedVersion').siblings('.multiselect-container');
  
               //Here I want to reselect the options that I have already selected after submitting my form
               onInitialized: function (option, checked) {
                var values = [];
                var $SelectedOptions = $(this).find('option:selected');
                $SelectedOptions.each(function () {
                    values.push($(this).text());
                });
            },

            enableFiltering: true,
            buttonWidth: '350px',
            maxHeight: 200,
            enableCaseInsensitiveFiltering: true,
        }); 

Open in new window




<td>
                       @Html.DropDownListFor(m => m.SelectedVersion, new SelectList(Model.VersionList, "Value", "Text"), new { @multiple = "multiple" } )
                    </td>

Open in new window

0
Hi,

I am working on C# MVC application.

I have payment integrated in my website. For payments, we call payment url which is loaded in iFrame.
We have no control on the form which opens in iFrame, as it captures credit card details.

Now, once user does the payment by clicking submit button in payment form, which (submit form) is in iFrame.

After successful/unsuccessful transaction we are receiving response in handler page.

After getting response in handler page we are losing session of our web application.

It works well in chrome but does not work in IE, Firefox.

What we should do so that we should not loose our session once the redirect happen.

Also, we see Chrome has same id before and after confirmation done.

But other browser gives us different session id's when returns from payment page.

Please advise the solution.

I have below configuration in my web.config already.
<httpCookies httpOnlyCookies="true" requireSSL="false" />
0
I am trying to increase the width of an Html.TextBoxFor control in an ASP.NET MVC 5 View page using razor syntax. I am using Visual Studio 2017. I created a css style (textboxfor) to increase the control's width as shown below but it is not working.

Below is the MVC View:


@using rgmsite.Models
@model LoginTestViewModel
@{
    ViewBag.Title = "Log in";
}

<style type="text/css">
    .textboxfor-width {
        width: 700px;
    }
</style>

<h2>SimpleTest</h2>
        <section id="loginForm">
            @using (Html.BeginForm("Login", "Account",
              new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post,
              new { @class = "form-horizontal", role = "form" }))
            {
                @Html.AntiForgeryToken()
                <div class="form-group">
                    @Html.TextBoxFor(m => m.Email,
                   new {  @class = "form-control textboxfor-width",
                       placeholder = "Enter email address to be used as your user name"
                   })
                </div>
            }
        </section>

Below is the View Model being used:


  public class LoginTestViewModel
  {
    public string Name { get; set; }
    public string Email { get; set; }
  }

Using a smaller width value such as 40px in the css .textboxforworks.  But there seems to be some limit imposed on the control preventing it from being wider (such as 400px) than the default. What needs to be done to make the …
0
I have the following codes in layout page in MVC project.
And I want to use mvc cache. e.g. within 8 hours using the cache. Is it possible?


<li>
                                            <span><a href="#"><i class="icon-bus"></i> Class A</a></span>
                                            <ul>
                                                @foreach (Domain.Fleet fHostAdmin in rv.FleetActiveList(locationName))
                                                {
                                                    if (fHostAdmin.FleetClassType.Substring(0, 1) == classAString)
                                                    {
                                                        <li><a href="@DomainHelper.Generic.GethttpType(Request.ServerVariables["HTTPS"], HttpContext.Current.Request.Url.Authority)/Home/Detail/@fHostAdmin.QuickFindKeyWord?fleetID=@fHostAdmin.Oid"><i class="icon-check"></i> <b>@fHostAdmin.FleetClassType</b>: @fHostAdmin.FleetName <label style="color:red;">(@fHostAdmin.FleetBaseRatePricingLabel)</label> </a></li>
                                                    }
                                                }
                                            </ul>

                                        </li>

Open in new window

0
Hi,
I start by saying this is the first project I have ever published and apologize in advance if I give you too much or too little information.
So, I published this MVC project to a business server.  It works but the data in the datatable is not showing. Although, when I just debug in Visual Studio there is data.
This project has 2 tabs:  
The first tab is to show the datatable in question which uses Entity Framework;  
The second tab also has a datatable(a yadcf) which shows data that is accessed via Ado.Net.
Data in the first tab does not show, while it does in the second tab.  


The datatable on the first tab references to this link:
 <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.js"></script>

While for the second tab I imported the yadcf datatable. Below is how I reference to it:
<script src="~/Yadcf/jquery.dataTables.yadcf.js"></script>  


Also, when I do F12 under the "Elements" I can see the references to the datatables(see attached photo).  Plus it looks like the datatable and its functionalities(search box, paging, column names) show up but without any data in it.


IN CASE YOU WANT TO SEE IT, THIS IS THE CODE OF THE INDEX PAGE WHICH INCLUDES THE DATATABLE:
`
@{
    ViewBag.Title = "Index";
}

<ul class="nav nav-tabs">
    <li class="active"><a data-toggle="tab" href="#firstTab">View All</a></li>
    <li><a data-toggle="tab" href="#secondTab">Add New</a></li>
  

Open in new window

0
Hi,
I published a MVC project to a business server.  It works but the data in the datatable is not showing.
Although, when I just debug in Visual Studio there is data.
This project has 2 tabs:  
The first tab is to show the datatable in question which uses Entity Framework;  
The second tab also has a datatable which shows data that is accessed via Ado.Net.
Data in the first tab does not show, while it does in the second tab.  


Could the problem be that while the datatable on the first tab references to this link
 <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.js"></script>

while for the second tab I imported the yadcf datatable
<script src="~/Yadcf/jquery.dataTables.yadcf.js"></script>   ?



FYI, when I published I used the below:

UNDER CONNECTION:
Publish method: Web Deploy
Server:  (Business Server Name)
Site name:  HelpDeskSupport
Username:  myUsername
Password:  myPassoword

UNDER SETTINGS:
Under "DBModel" as the datasource I added the SQL Server name with its username and password.
I checked the "Use this connection string at runtime..."



Could you please help me figure out what I have done wrong? Thank you.
0
I am new in Web API, and I want to have a step by step guide using VS 2010 and VB.NET. An Important concept is how to secure the API... If what I need is achievable... can any of you recommend a book for that. I appreciate your help
0
Hi,

I need your help!

I can upload any file type to a folder and save the name and path to the database.
I'm also able to list all the attached files based on the selected record.

My next step is to let the user view what they have uploaded to the server folder.

I'm not sure how to do this step

do you have any example that might help me?

//when the user click on the button ViewFileBtn
I need to be able to upload the file and give them the option to save or view the file. 


Do I have to create a popup window to uploaded the downloaded file?



@foreach (var FileUploadedList in Model.UploadedFilesList)
                {
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            @FileUploadedList.FileID <span>| </span>@FileUploadedList.Name <span> | </span> @FileUploadedList.Path
                            <button id="ViewFileBtn" name="ViewFileBtn" class="btn btn-default" type="button" style="margin-top:10px;margin-bottom:10px;" value="@FileUploadedList.FileID">
                                View File
                            </button>
                           

                        </h3>
                    </div>
                }

Open in new window

0
Hi,

This is my first linq and I'm not sure what I'm doing.

I need your help please.

I have to tables:

Table:
CABR_RuleIdentifier
RuleIdentifierId
RuleSetId
RuleIdentifier
IsActive


Table:
CABR_RuleDetail
RuleDetailId
isActive
RuleSetId
RuleIdentifierId
Version
Environment


I need to do this in linq:

SELECT RuleDetailId, isActive, RuleSetId, RuleIdentifierId, Version, Environment
FROM CABR_RuleDetail
LEFT JOIN CABR_RuleIdentifier
ON CABR_RuleDetail.RuleSetId = CABR_RuleIdentifier.RuleSetId; 


           CABR_RuleDetail RuleDetailResult = new CABR_RuleDetail();
            var result = from CABR_RuleDetail in RD
                         join CABR_RuleIdentifier in RI
                         on RD.RuleSetId equals RI.RuleSetId into ResultData
                         from RuleDetailResult in ResultData.DefaultIfEmpty()
                         select new
                         {
                             CABR_RuleDetail.RuleDescription,
                             CABR_RuleDetail.RuleDetailId,
                             CABR_RuleDetail.isActive,
                             CABR_RuleDetail.RuleSetId,
                             CABR_RuleDetail.RuleIdentifierId,
                             CABR_RuleDetail.Version,
                             CABR_RuleDetail.Environment,
                             CABR_RuleIdentifier.RuleIdentifier
                         };

Open in new window

0
Hello Experts,

I have MVC 5 asp.net application(using jquery), On a page if I click Add where it shows modal popup with two fields Name and Age  and it has Required field validators. It shows when try to save without entering both the fields and on cancel button the modal popup close and it goes back to page(which has grid). When I click row Edit on grid, the popup shows the Validation messages under the textbox.

<div class="col-md-3 col-lg-3 col-3">
                            <div class="form-group m-b-40">
                                <input type="text" id="Name" name="Name" value="" class="form-control" required="required" autofocus="autofocus">
                                <span class="bar"></span>
                                <label for="Name">Name*</label>
                            </div>
                               <div class="form-group m-b-40">
                                <input type="text" id="Age" name="Name" value="" class="form-control" required="required" autofocus="autofocus">
                                <span class="bar"></span>
                                <label for="Age">Age*</label>
                            </div>
                        </div>

Open in new window


I tried below suggestions this(on cancel button) and still same issue
https://stackoverflow.com/questions/2798427/how-do-i-clear-mvc-client-side-validation-errors-when-a-cancel-button-is-clicked

Thanks,
ASPDEV
0
Hi,
I am displaying data on the ViewAllTasks page which has a delete, an edit and an add.  They all work except for the update one.  I do not get any errors and the program seems to run fine but the database is not updated and the view is not updated as well.
The add does something similar and it works:  it inserts a record in the database and the view is updated via the loadData() javascript.  What is it that I am doing wrong?  Please help.  Thank you

JAVASCRIPT:
//Load Data in Table when documents is ready
$(document).ready(function () {
    loadData();
});

//Load Data function
function loadData() {
    $.ajax({
        url: "/Tickets/ListITTasks",
        type: "GET",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (result) {
            var html = '';
            $.each(result, function (key, item) {
                html += '<tr>';
                html += '<td>' + item.ITNumber + '</td>';
                html += '<td>' + item.ITDescription + '</td>';
                html += '<td>' + item.ITEnterDate + '</td>';
                html += '<td>' + item.ITAssignedTo + '</td>';
                html += '<td>' + item.ITEstimatedCompletion + '</td>';
                html += '<td>' + item.ITPriority + '</td>';
                html += '<td>' + item.ITFrom + '</td>';
                html += '<td>' + item.ITStatus + '</td>';
                html += '<td><a href="#" onclick="return getbyTicketNumber(' 

Open in new window

0
Hi,
I have a main view which has a "Comments" link on each row that when clicked it opens up a partial view. The partial view displays a table and textboxes, and an "Add" button that when clicked it adds the data entered in the textboxes to the table.

The first time I click on comments, I add data to the textboxes and hit the Add button and everything works.

The problem is:  when I open the partial view from another record(by clicking on Comments) and add data to the textboxes, after I click on add it adds an extra blank row.  It is as if the add button is clicked twice.  Could you please help me solve this issue?  The code I am using is below.
Thank you very much.

**PARTIAL VIEW:**
        @model IEnumerable<HelpDeskSupport.Models.Comment>

        <html>
        <body>
    <table class="table table-striped table-bordered" cellpadding="0" cellspacing="0" border="0" width="1500" id="tblComments">
        <thead>
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.TicketNumber)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Comment1)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.AssignedTo)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CreatedBy)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Date)

Open in new window

0
Hi,
I have a main form displaying data.  Then I have a "Comments" link on each row and on the click of it a partial view with a table opens up.  The partial view is to view/add comments and other data.  In this partial view, after the table, there are textboxes I can fill with data.  After adding data I click on "Add" and when I am done I would click on "Save" and whatever I typed in the textboxes is entered in the database.  This all works and gives you an idea of what I am working with(see attached pics as well).  

What I am looking for now is a way to fill the Ticket Number textbox(on the partial view) with the number from the Number field(on main form).  Also, this number should not be edited on the partial.  How can I achieve that?

I have been unable to find a solution.  Please help.  Thank you.

THIS IS THE CODE IN THE CONTROLLER:
//VIEW ALL COMMENTS AND DISPLAY IN PARTIAL
        [HttpPost]
        public ActionResult ViewComments(int ticketNum)
        {
            List<Comment> AllComments = new List<Comment>();
            using (DBModel db = new DBModel())
                AllComments = db.Comments.Where(x => x.TicketNumber == ticketNum).ToList();

            return PartialView("ViewComments", AllComments);
        }


//INSERT COMMENT
        public JsonResult InsertComments(List<Comment> commentsArray)
        {
            using (DBModel db = new DBModel())
            {
                //Truncate Table to delete all comments. 

Open in new window

0

.NET MVC

427

Solutions

311

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
>