问:
Query result from array string with numbers to array string text?
I have two SQL Server tables.

First table: Product

Id
Title
Tags

1
P1583
2,5

2
P1234
1,3

3
P1456
1

Second table - Tag:

Id
Title

1
Pants

2
Shorts

3
Shirts

4
Tshirts

5
Skirts

I want this result

ProductId
Title
TagName

1
P1583
Short,Skirts

2
P1234
Pants,Shirts

3
P1456
Pants

How can I write the query?

```<code>SELECT
    P.Id AS ProductId,
    P.Title AS Title,
    ????
FROM
    Product P
LEFT JOIN
    Tag T ON T.Id = P.Tags  --- (this is not working)
</code>```

答:
your table

```<code>declare @r TABLE (
   Id    int  NOT NULL
  ,Title VARCHAR(10) NOT NULL
  ,Tags  VARCHAR(30) NOT NULL
);
INSERT INTO @r(Id,Title,Tags) VALUES (1,'P1583','2,5');
INSERT INTO @r(Id,Title,Tags) VALUES (2,'P1234','1,3');
INSERT INTO @r(Id,Title,Tags) VALUES (3,'P1456','1');

declare @t TABLE (
   Id    int  NOT NULL PRIMARY KEY
  ,Title VARCHAR(70) NOT NULL
);
INSERT INTO @t(Id,Title) VALUES (1,'Pants');
INSERT INTO @t(Id,Title) VALUES (2,'Shorts');
INSERT INTO @t(Id,Title) VALUES (3,'Shirts');
INSERT INTO @t(Id,Title) VALUES (4,'Tshirts');
INSERT INTO @t(Id,Title) VALUES (5,'Skirts');
</code>```

query to produce result the tag should be splitted and merge again with the title of second table

```<code>with t as(
SELECT Id,Title,
    PARSENAME(REPLACE(Tags,',','.'),2) 'Tag1' ,
    PARSENAME(REPLACE(Tags,',','.'),1) 'Tag2'
FROM @r)
select t.id,t.Title,concat(t1.Title,iif(t1.Title is null,'',','),t2.Title)
tagName from t
full join @t t1 on t1.id=t.Tag1
join @t t2 on t2.id=t.Tag2
</code>```

Body:
I have two SQL Server tables.

First table: Product

Id
Title
Tags

1
P1583
2,5

2
P1234
1,3

3
P1456
1

Second table - Tag:

Id
Title

1
Pants

2
Shorts

3
Shirts

4
Tshirts

5
Skirts

I want this result

ProductId
Title
TagName

1
P1583
Short,Skirts

2
P1234
Pants,Shirts

3
P1456
Pants

How can I write the query?

SELECT
    P.Id AS ProductId,
    P.Title AS Title,
    ????
FROM
    Product P
LEFT JOIN
    Tag T ON T.Id = P.Tags  --- (this is not working)

Body:
your table

declare @r TABLE (
   Id    int  NOT NULL
  ,Title VARCHAR(10) NOT NULL
  ,Tags  VARCHAR(30) NOT NULL
);
INSERT INTO @r(Id,Title,Tags) VALUES (1,'P1583','2,5');
INSERT INTO @r(Id,Title,Tags) VALUES (2,'P1234','1,3');
INSERT INTO @r(Id,Title,Tags) VALUES (3,'P1456','1');

declare @t TABLE (
   Id    int  NOT NULL PRIMARY KEY
  ,Title VARCHAR(70) NOT NULL
);
INSERT INTO @t(Id,Title) VALUES (1,'Pants');
INSERT INTO @t(Id,Title) VALUES (2,'Shorts');
INSERT INTO @t(Id,Title) VALUES (3,'Shirts');
INSERT INTO @t(Id,Title) VALUES (4,'Tshirts');
INSERT INTO @t(Id,Title) VALUES (5,'Skirts');

query to produce result the tag should be splitted and merge again with the title of second table

with t as(
SELECT Id,Title,
    PARSENAME(REPLACE(Tags,',','.'),2) 'Tag1' ,
    PARSENAME(REPLACE(Tags,',','.'),1) 'Tag2'
FROM @r)
select t.id,t.Title,concat(t1.Title,iif(t1.Title is null,'',','),t2.Title)
tagName from t
full join @t t1 on t1.id=t.Tag1
join @t t2 on t2.id=t.Tag2


来源: stackexchange

问:
Laravel project, how to make public folder not accessable by root
I have my Laravel project that is hosted on a server, I made a copy of that project for testing and development on my local pc, but there is a difference that I don't know how to solve. On my local pc I do not need to specify public folder to access css files and other stuff, but on my server I have to specify, otherwise I doesn't find those files in public folder.
Example code on server:

```<code><link rel="stylesheet" href="/public/css/main.css">
</code>```

And on my local pc

```<code><link rel="stylesheet" href="/css/main.css">
</code>```

So I would love to make this thing the same on my local project, because now everytime I push changes to the server I need to add public to all the stuff and that's annoying. If I understand correctly it is done for security purposes, but I don't know how to make it on my project.

答:
Use Laravel asset() function like below,</p>
```<code><link rel="stylesheet" href="{{asset('css/main.css')}}">
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have my Laravel project that is hosted on a server, I made a copy of that project for testing and development on my local pc, but there is a difference that I don't know how to solve. On my local pc I do not need to specify public folder to access css files and other stuff, but on my server I have to specify, otherwise I doesn't find those files in public folder.
Example code on server:

<link rel="stylesheet" href="/public/css/main.css">

And on my local pc

<link rel="stylesheet" href="/css/main.css">

So I would love to make this thing the same on my local project, because now everytime I push changes to the server I need to add public to all the stuff and that's annoying. If I understand correctly it is done for security purposes, but I don't know how to make it on my project.

Body:
Use Laravel asset() function like below,

<link rel="stylesheet" href="{{asset('css/main.css')}}">


问:
How to configure mapstruct in gradle project
I tried to add mapstruct to gradle spring boot project.
here is related part of build.gradle file:

```<code>    implementation 'org.mapstruct:mapstruct:1.4.2.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok-mapstruct-binding:0.2.0'

</code>```

here is my interface:

```<code>@Mapper
public interface LogMessageMapper {

    @Mapping(target = "content", ignore = true)
    LogMessageDto toLogMessageDto(LogMessage source);

    @AfterMapping
    default void setContentString(LogMessage source, @MappingTarget LogMessageDto target) {
        target.setContent(source.getContent().toString());
    }
}
</code>```

i received generated implementation of my mapper interface in two places:
first expected but not used by my code:
build/generated/sources/.../LogMessageMapperImpl

second unexpected but used by my code:
app/src/main/generated/.../LogMessageMapperImpl

How i have to configure gradle to make my code use properly generated classes? Thanks for any suggestions.

UPD: unexpected implementation appears only on start app from intellij idea or running tests from idea. On gradle clean build is generated only expected, desirable implementation and build is successful, tests as well.

答: After removing .idea folder from project and reopen in idea problem desappeared.</p>

Body:
I tried to add mapstruct to gradle spring boot project.
here is related part of build.gradle file:

    implementation 'org.mapstruct:mapstruct:1.4.2.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok-mapstruct-binding:0.2.0'

here is my interface:

@Mapper
public interface LogMessageMapper {

    @Mapping(target = "content", ignore = true)
    LogMessageDto toLogMessageDto(LogMessage source);

    @AfterMapping
    default void setContentString(LogMessage source, @MappingTarget LogMessageDto target) {
        target.setContent(source.getContent().toString());
    }
}

i received generated implementation of my mapper interface in two places:
first expected but not used by my code:
build/generated/sources/.../LogMessageMapperImpl

second unexpected but used by my code:
app/src/main/generated/.../LogMessageMapperImpl

How i have to configure gradle to make my code use properly generated classes? Thanks for any suggestions.

UPD: unexpected implementation appears only on start app from intellij idea or running tests from idea. On gradle clean build is generated only expected, desirable implementation and build is successful, tests as well.


问:
Asp.net controls are not accessible in code behind
I have a project that was previously built by someone else. When I try to add a new control to the page, I can't access it in the code behind. When I try to access it there's an error message that the Control is not defined in the current context.

```<code><%@ Page Language="C#" MasterPageFile="~/HRMS.Master" AutoEventWireup="true"     CodeBehind="manageEmployee.aspx.cs" Inherits="HRMS.manageEmployee" Title="Untitled Page" %>

<%@ Register Assembly="eWorld.UI" Namespace="eWorld.UI" TagPrefix="ew" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
    document.getElementById("employee").setAttribute("class", "selected");
    </script>
<!--OPEN CONTENT DIV-->

     <asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>
    <!-- Only this area is updated on PostBack -->

<div class="manage_employ">

    <ul>
        <li style="margin-top:10px; margin-bottom:15px"><input type="image" src="images/img_manageEmployee01.png"/></li>
    </ul>

    <ul>
        <li>First name</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtFirstName"/></li>
        <asp:RequiredFieldValidator ID="validatorFirstName" runat="server" ErrorMessage="*" ControlToValidate="txtFirstName"></asp:RequiredFieldValidator>
        <li>Last name</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtLastName"/></li>
        <asp:RequiredFieldValidator ID="validatorLastname" runat="server" ErrorMessage="*" ControlToValidate="txtLastName"></asp:RequiredFieldValidator>
    </ul>

    <ul>
        <li>CNIC</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtCNIC"/></li>
        <asp:RequiredFieldValidator ID="validatorCNIC" runat="server" ErrorMessage="*" ControlToValidate="txtCNIC"></asp:RequiredFieldValidator>
        <li>Blood Group</li>
        <li><asp:DropDownList runat="server" class="text_input" id="ddlBloodGroup">
        <asp:ListItem>A+</asp:ListItem>
        <asp:ListItem>B+</asp:ListItem>
        <asp:ListItem>AB+</asp:ListItem>
        <asp:ListItem>A-</asp:ListItem>
        <asp:ListItem>B-</asp:ListItem>
        <asp:ListItem>AB-</asp:ListItem>
        <asp:ListItem>O+</asp:ListItem>
        <asp:ListItem>O-</asp:ListItem>
        </asp:DropDownList>
        </li>
    </ul>

    <ul>
        <li>Mobile</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtMobile"/></li>
        <asp:RequiredFieldValidator ID="validatorMobile" runat="server" ErrorMessage="*" ControlToValidate="txtMobile"></asp:RequiredFieldValidator>
        <li>Phone</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtPhone"/></li>
    </ul>

    <ul>

    </ul>

    <ul>
        <li>E-Mail</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtEmail"/></li>
        <asp:RegularExpressionValidator ID="valEmail" ControlToValidate="txtEmail" runat="server" ErrorMessage="*" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
            <li>Maritial Status</li>
            <li>
            <asp:RadioButton ID="rbtnMarried" AutoPostBack="true" runat="server" oncheckedchanged="rbtnMarried_CheckedChanged"/>Married
            <asp:RadioButton ID="rbtnUnmarried" AutoPostBack="true" runat="server"
                    oncheckedchanged="rbtnUnmarried_CheckedChanged"/>Unmarried
            </li>
            </ContentTemplate>
        </asp:UpdatePanel>
    </ul>

    <ul>
        <li>Permanant Address</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtPermanantAddress"/></li>
        <asp:RequiredFieldValidator ID="validatorPAddress" runat="server" ErrorMessage="*" ControlToValidate="txtPermanantAddress"></asp:RequiredFieldValidator>
        <li>Temporary Address</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtTemporaryAddress"/></li>
        <asp:RequiredFieldValidator ID="validatorTAddress" runat="server" ErrorMessage="*" ControlToValidate="txtTemporaryAddress"></asp:RequiredFieldValidator>
    </ul>

    <ul>
        <li>Salary</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtSalary"/></li>
        <asp:RequiredFieldValidator ID="validatorSalary" runat="server" ErrorMessage="*" ControlToValidate="txtSalary"></asp:RequiredFieldValidator>
        <li>Joining Date</li>

             <li>
        <%--<ew:calendarpopup ID="calJoiningDate" runat="server"></ew:calendarpopup>--%>
                  <asp:TextBox ID="CalJoiningDate1" runat="server" CssClass="text_input"></asp:TextBox>
                  <cc1:CalendarExtender ID="CalJoiningDate1_CalendarExtender" runat="server"
                       Enabled="True" TargetControlID="CalJoiningDate1">
                  </cc1:CalendarExtender>
        </li>

    </ul>
    <ul>
        <li>Job Area</li>
        <li><asp:DropDownList runat="server" class="text_input" id="ddlJobArea"/></li>
        <li>Desigantion</li>
        <li><asp:DropDownList runat="server" class="text_input" id="ddlDesignation"/></li>
    </ul>

    <asp:UpdatePanel ID="updatePnl" runat="server">
    <ContentTemplate>
    <div>
    <ul>
        <li style="margin-top:20px; margin-bottom:15px"><input type="image" src="images/img_jobHistory.png"  /></li>
    </ul>

    <ul>
    <li>Company</li>
   <%--<asp:DropDownList runat="server" class="text_input" id="ddlCompany"
              onselectedindexchanged="ddlCompany_SelectedIndexChanged"/>--%>
          <li><asp:TextBox ID="CompanyNames" runat="server" CssClass="text_input"></asp:TextBox>
               <cc1:AutoCompleteExtender ID="CompanyNames_AutoCompleteExtender" runat="server"
                    DelimiterCharacters="" Enabled="True" ServicePath="getCompanies.asmx" ServiceMethod="getCompaniesMethod" MinimumPrefixLength="1"
                    TargetControlID="CompanyNames" UseContextKey="True">
               </cc1:AutoCompleteExtender>
               <li>Job Duration</li>
               <li>
                    <asp:TextBox ID="txtJobDuration" runat="server" class="text_input" />
               </li>
               <asp:RequiredFieldValidator ID="validatorJobDuration" runat="server"
                    ControlToValidate="txtJobDuration" ErrorMessage="*"
                    ValidationGroup="jobHistory"></asp:RequiredFieldValidator>
         </li>
    </ul>

    <ul>
    <li>Job Area</li>
    <li><asp:DropDownList runat="server" class="text_input" id="ddlJobHistJobArea"/></li>
    <li>Designation</li>
    <li><asp:DropDownList runat="server" class="text_input" id="ddlJobHistoryDesignation"/></li>
    </ul>

    <ul>
    <li>Last Drawn Salary</li>
    <li><asp:TextBox runat="server" class="text_input" id="txtLastDrawnSalary"/>
         </li>
        <asp:RequiredFieldValidator ID="validatorLastDrawnSalary" runat="server" ValidationGroup="jobHistory" ErrorMessage="*" ControlToValidate="txtLastDrawnSalary"></asp:RequiredFieldValidator>
    </ul>

    <ul>
        <li style="margin-left:160px">
            <asp:ImageButton src="images/btn_Add.png" runat="server" ID="btnAddJobHistory" onclick="btnAddJobHistory_Click" CausesValidation="True" ValidationGroup="jobHistory"/>
            <asp:ImageButton src="images/btnReset.png" runat="server" ID="btnResetJH" CausesValidation="False" onclick="btnResetJH_Click"/>
        </li>
    </ul>

    <ul style="margin-left:30px">
    <asp:GridView ID="grdJobHistory" runat="server" AutoGenerateColumns="False" Width="798px"
            AllowPaging="True"
        onpageindexchanging="grdJobHistory_PageIndexChanging"
        onrowcommand="grdJobHistory_RowCommand"
            onrowdeleting="grdJobHistory_RowDeleting"
            onrowediting="grdJobHistory_RowEditing" Font-Bold="True"
            Font-Names="Calibri" Font-Size="Medium" ForeColor="White" PageSize="5">
            <Columns>
                <asp:BoundField DataField="EmployeeExperianceId"
                    HeaderText="EmployeeExperianceId" />
                <asp:BoundField HeaderText="Company" DataField="CompanyName" ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField DataField="JobAreaName" HeaderText="Job Area" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Smaller" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Designation" DataField="DesignationName"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Experiance Duration" DataField="ExperianceDuration"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Salary" DataField="LastDrawnSalary" ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:TemplateField AccessibleHeaderText="Edit" HeaderText="Edit">
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="images/updateIcon.png" CausesValidation="False" CommandName="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeExperianceId") %>'/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField AccessibleHeaderText="Delete" HeaderText="Delete">
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="images/deleteIcon.png" CausesValidation="False" CommandName="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeExperianceId") %>' OnClientClick="return confirm('Are you sure you want to delete this record...');"/>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <HeaderStyle BackColor="#5D92B9" BorderStyle="None" />
            <AlternatingRowStyle BackColor="#AAAAAA" />
        </asp:GridView>
    </ul>

    </div>

    <div>
    <ul>
        <li style="margin-top:20px; margin-bottom:15px"><input type="image" src="images/img_skillDetail.png"  /></li>
    </ul>

    <ul>
        <li>Skill</li>
        <!--<li><asp:DropDownList runat="server" class="text_input" id="ddlSkill"/></li>-->
        <li>
             <asp:TextBox ID="SkillAutoComplete" runat="server" CssClass="text_input"></asp:TextBox>
             <cc1:AutoCompleteExtender ID="SkillAutoComplete_AutoCompleteExtender"
                  runat="server" DelimiterCharacters="" Enabled="True" ServicePath="getSkills.asmx" ServiceMethod="getAllSkills" MinimumPrefixLength="1"
                  TargetControlID="SkillAutoComplete">
             </cc1:AutoCompleteExtender>
         </li>
        <li>Skill Detail</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtSkillDetail"/></li>
        <asp:RequiredFieldValidator ID="validatorSkillDetail" runat="server" ValidationGroup="skill" ErrorMessage="*" ControlToValidate="txtSkillDetail"></asp:RequiredFieldValidator>
    </ul>

    <ul>
        <li style="margin-left:160px">
            <asp:ImageButton src="images/btn_Add.png" runat="server" ID="btnAddSkill" CausesValidation="True" ValidationGroup="skill" onclick="btnAddSkill_Click"/>
            <asp:ImageButton src="images/btnReset.png" runat="server" ID="btnResetSkill" CausesValidation="False" onclick="btnResetSkill_Click"/>
        </li>
    </ul>

    <ul style="margin-left:30px">
    <asp:GridView ID="grdSkill" runat="server" AutoGenerateColumns="False" Width="798px"
            AllowPaging="True"
        onpageindexchanging="grdSkill_PageIndexChanging"
        onrowcommand="grdSkill_RowCommand"
            onrowdeleting="grdSkill_RowDeleting"
            onrowediting="grdSkill_RowEditing" Font-Bold="True"
            Font-Names="Calibri" Font-Size="Medium" ForeColor="White" PageSize="5">
            <Columns>
                <asp:BoundField HeaderText="EmployeeSkillId" DataField="EmployeeSkillId" >
                </asp:BoundField>
                <asp:BoundField DataField="SkillName" HeaderText="Skill Name" ReadOnly="True">
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Skill Detail" DataField="SkillDetail"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="images/updateIcon.png" CausesValidation="false" CommandName="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeSkillId") %>'/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="images/deleteIcon.png" CommandName="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeSkillId") %>' OnClientClick="return confirm('Are you sure you want to delete this record...');"/>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <HeaderStyle BackColor="#5D92B9" BorderStyle="None" />
            <AlternatingRowStyle BackColor="#AAAAAA" />
        </asp:GridView>
    </ul>
    </div>

    <div>
    <ul>
        <li style="margin-top:20px; margin-left:20px; margin-bottom:15px"><input type="image" src="images/img_qualificationDetail.png"  /></li>
    </ul>

    <ul>
        <li>Course</li>
        <li><asp:DropDownList runat="server" class="text_input" id="ddlCourse"/></li>
        <li>Institution</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtInstitution"/></li>
        <asp:RequiredFieldValidator ID="validatorInsitution" runat="server" ValidationGroup="course" ErrorMessage="*" ControlToValidate="txtInstitution"></asp:RequiredFieldValidator>
    </ul>

    <ul>
        <li>Duration</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtCourseDuration"/></li>
        <asp:RequiredFieldValidator ID="validatorDuration" runat="server" ValidationGroup="course" ErrorMessage="*" ControlToValidate="txtCourseDuration"></asp:RequiredFieldValidator>
        <li>Passing Year</li>
        <li>
             <asp:TextBox ID="calPassingYear1" runat="server" CssClass="text_input"></asp:TextBox>

        </li>
        <!--<li><ew:CalendarPopup ID="calPassingYear" runat="server"></ew:CalendarPopup></li>-->
    </ul>

    <ul>
        <li>Marks/Percentage/GPA</li>
        <li><asp:TextBox runat="server" class="text_input" id="txtMarksPercentage"/></li>
        <asp:RequiredFieldValidator ID="validatorMarks" runat="server" ValidationGroup="course" ErrorMessage="*" ControlToValidate="txtMarksPercentage"></asp:RequiredFieldValidator>
        <li style="margin-left:160px">
        <asp:ImageButton src="images/btn_Add.png" runat="server" ID="btnAddCourse" CausesValidation="True" onclick="btnAddCourse_Click" ValidationGroup="course"/>
        <asp:ImageButton src="images/btnReset.png" runat="server" ID="btnResetCourse" CausesValidation="False" onclick="btnResetCourse_Click" />
        </li>
    </ul>

    <ul style="margin-left:30px">
    <asp:GridView ID="grdCourse" runat="server" AutoGenerateColumns="False" Width="798px"
            AllowPaging="True"
        onpageindexchanging="grdCourse_PageIndexChanging"
        onrowcommand="grdCourse_RowCommand"
            onrowdeleting="grdCourse_RowDeleting"
            onrowediting="grdCourse_RowEditing" Font-Bold="True"
            Font-Names="Calibri" Font-Size="Medium" ForeColor="White" PageSize="5">
            <Columns>
                <asp:BoundField DataField="EmployeeQualificationId"
                    HeaderText="EmployeeQualificationId" />
                <asp:BoundField HeaderText="Course" DataField="CourseTitle" ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Institution" DataField="InstitutionName"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Duration" DataField="Duration"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Passing Year" DataField="YearOfPassing"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Marks/Percentage/GPA" DataField="MarksPercentage"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="images/updateIcon.png" CausesValidation="false" CommandName="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeQualificationId") %>'/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="images/deleteIcon.png" CommandName="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeQualificationId") %>' OnClientClick="return confirm('Are you sure you want to delete this record...');"/>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <HeaderStyle BackColor="#5D92B9" BorderStyle="None" />
            <AlternatingRowStyle BackColor="#AAAAAA" />
        </asp:GridView>
    </ul>
    </div>
    </ContentTemplate>
      </asp:UpdatePanel>
    <ul>
       <li style="margin-left:90px; margin-bottom:10px;">
       <asp:ImageButton ID="btnSubmit" AlternateText="submit button" runat="server" src="images/btn_Submit.png" onclick="btnSubmit_Click"/>
       </li>
    </ul>
</div>
            <!--CLOSE CONTENT DIV-->

</asp:Content>
</code>```

For Example:

When I was trying to add some ASP.NET server side controls like <asp:testBox id="txtBox" runat="server"/> they were not accessible in the code behind.:

Error: txtBox is not defined in the current Context ...

What am I doing wrong?

答:
This happens especially with older stuff in visual studio.

In 1.1 (before "partial classes") you could always see the control declarations in the code-behind.

In later versions, they moved that into a cs.designer file (so now you've got partial classes -- part in the .cs.designer file, and part in the .cs file).

If you're working with a visual studio "project", then you can open the cs.designer file, and add your control.  Just look at how all of the other controls are declared -- that's all you have to do.

If you're working with a visual studio "website", then you're out of luck.  There's no way to view or edit the cs.designer file, because it isn't there until the website is compiled.

Body:
I have a project that was previously built by someone else. When I try to add a new control to the page, I can't access it in the code behind. When I try to access it there's an error message that the Control is not defined in the current context.

<%@ Page Language="C#" MasterPageFile="~/HRMS.Master" AutoEventWireup="true"     CodeBehind="manageEmployee.aspx.cs" Inherits="HRMS.manageEmployee" Title="Untitled Page" %>

<%@ Register Assembly="eWorld.UI" Namespace="eWorld.UI" TagPrefix="ew" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

     <asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>

<input type="image" src="images/img_manageEmployee01.png"/>

First name

<asp:TextBox runat="server" class="text_input" id="txtFirstName"/>

        <asp:RequiredFieldValidator ID="validatorFirstName" runat="server" ErrorMessage="*" ControlToValidate="txtFirstName"></asp:RequiredFieldValidator>

Last name

<asp:TextBox runat="server" class="text_input" id="txtLastName"/>

        <asp:RequiredFieldValidator ID="validatorLastname" runat="server" ErrorMessage="*" ControlToValidate="txtLastName"></asp:RequiredFieldValidator>

CNIC

<asp:TextBox runat="server" class="text_input" id="txtCNIC"/>

        <asp:RequiredFieldValidator ID="validatorCNIC" runat="server" ErrorMessage="*" ControlToValidate="txtCNIC"></asp:RequiredFieldValidator>

Blood Group

<asp:DropDownList runat="server" class="text_input" id="ddlBloodGroup">
        <asp:ListItem>A+</asp:ListItem>
        <asp:ListItem>B+</asp:ListItem>
        <asp:ListItem>AB+</asp:ListItem>
        <asp:ListItem>A-</asp:ListItem>
        <asp:ListItem>B-</asp:ListItem>
        <asp:ListItem>AB-</asp:ListItem>
        <asp:ListItem>O+</asp:ListItem>
        <asp:ListItem>O-</asp:ListItem>
        </asp:DropDownList>

Mobile

<asp:TextBox runat="server" class="text_input" id="txtMobile"/>

        <asp:RequiredFieldValidator ID="validatorMobile" runat="server" ErrorMessage="*" ControlToValidate="txtMobile"></asp:RequiredFieldValidator>

Phone

<asp:TextBox runat="server" class="text_input" id="txtPhone"/>

E-Mail

<asp:TextBox runat="server" class="text_input" id="txtEmail"/>

        <asp:RegularExpressionValidator ID="valEmail" ControlToValidate="txtEmail" runat="server" ErrorMessage="*" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>

Maritial Status

            <asp:RadioButton ID="rbtnMarried" AutoPostBack="true" runat="server" oncheckedchanged="rbtnMarried_CheckedChanged"/>Married
            <asp:RadioButton ID="rbtnUnmarried" AutoPostBack="true" runat="server"
                    oncheckedchanged="rbtnUnmarried_CheckedChanged"/>Unmarried

            </ContentTemplate>
        </asp:UpdatePanel>

Permanant Address

<asp:TextBox runat="server" class="text_input" id="txtPermanantAddress"/>

        <asp:RequiredFieldValidator ID="validatorPAddress" runat="server" ErrorMessage="*" ControlToValidate="txtPermanantAddress"></asp:RequiredFieldValidator>

Temporary Address

<asp:TextBox runat="server" class="text_input" id="txtTemporaryAddress"/>

        <asp:RequiredFieldValidator ID="validatorTAddress" runat="server" ErrorMessage="*" ControlToValidate="txtTemporaryAddress"></asp:RequiredFieldValidator>

Salary

<asp:TextBox runat="server" class="text_input" id="txtSalary"/>

        <asp:RequiredFieldValidator ID="validatorSalary" runat="server" ErrorMessage="*" ControlToValidate="txtSalary"></asp:RequiredFieldValidator>

Joining Date

        <%--<ew:calendarpopup ID="calJoiningDate" runat="server"></ew:calendarpopup>--%>
                  <asp:TextBox ID="CalJoiningDate1" runat="server" CssClass="text_input"></asp:TextBox>
                  <cc1:CalendarExtender ID="CalJoiningDate1_CalendarExtender" runat="server"
                       Enabled="True" TargetControlID="CalJoiningDate1">
                  </cc1:CalendarExtender>

Job Area

<asp:DropDownList runat="server" class="text_input" id="ddlJobArea"/>

Desigantion

<asp:DropDownList runat="server" class="text_input" id="ddlDesignation"/>

    <asp:UpdatePanel ID="updatePnl" runat="server">
    <ContentTemplate>

<input type="image" src="images/img_jobHistory.png"  />

Company

   <%--<asp:DropDownList runat="server" class="text_input" id="ddlCompany"
              onselectedindexchanged="ddlCompany_SelectedIndexChanged"/>--%>

<asp:TextBox ID="CompanyNames" runat="server" CssClass="text_input"></asp:TextBox>
               <cc1:AutoCompleteExtender ID="CompanyNames_AutoCompleteExtender" runat="server"
                    DelimiterCharacters="" Enabled="True" ServicePath="getCompanies.asmx" ServiceMethod="getCompaniesMethod" MinimumPrefixLength="1"
                    TargetControlID="CompanyNames" UseContextKey="True">
               </cc1:AutoCompleteExtender>

Job Duration

                    <asp:TextBox ID="txtJobDuration" runat="server" class="text_input" />

               <asp:RequiredFieldValidator ID="validatorJobDuration" runat="server"
                    ControlToValidate="txtJobDuration" ErrorMessage="*"
                    ValidationGroup="jobHistory"></asp:RequiredFieldValidator>

Job Area

<asp:DropDownList runat="server" class="text_input" id="ddlJobHistJobArea"/>

Designation

<asp:DropDownList runat="server" class="text_input" id="ddlJobHistoryDesignation"/>

Last Drawn Salary

<asp:TextBox runat="server" class="text_input" id="txtLastDrawnSalary"/>

        <asp:RequiredFieldValidator ID="validatorLastDrawnSalary" runat="server" ValidationGroup="jobHistory" ErrorMessage="*" ControlToValidate="txtLastDrawnSalary"></asp:RequiredFieldValidator>

            <asp:ImageButton src="images/btn_Add.png" runat="server" ID="btnAddJobHistory" onclick="btnAddJobHistory_Click" CausesValidation="True" ValidationGroup="jobHistory"/>
            <asp:ImageButton src="images/btnReset.png" runat="server" ID="btnResetJH" CausesValidation="False" onclick="btnResetJH_Click"/>

    <asp:GridView ID="grdJobHistory" runat="server" AutoGenerateColumns="False" Width="798px"
            AllowPaging="True"
        onpageindexchanging="grdJobHistory_PageIndexChanging"
        onrowcommand="grdJobHistory_RowCommand"
            onrowdeleting="grdJobHistory_RowDeleting"
            onrowediting="grdJobHistory_RowEditing" Font-Bold="True"
            Font-Names="Calibri" Font-Size="Medium" ForeColor="White" PageSize="5">
            <Columns>
                <asp:BoundField DataField="EmployeeExperianceId"
                    HeaderText="EmployeeExperianceId" />
                <asp:BoundField HeaderText="Company" DataField="CompanyName" ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField DataField="JobAreaName" HeaderText="Job Area" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Smaller" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Designation" DataField="DesignationName"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Experiance Duration" DataField="ExperianceDuration"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Salary" DataField="LastDrawnSalary" ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:TemplateField AccessibleHeaderText="Edit" HeaderText="Edit">
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="images/updateIcon.png" CausesValidation="False" CommandName="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeExperianceId") %>'/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField AccessibleHeaderText="Delete" HeaderText="Delete">
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="images/deleteIcon.png" CausesValidation="False" CommandName="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeExperianceId") %>' OnClientClick="return confirm('Are you sure you want to delete this record...');"/>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <HeaderStyle BackColor="#5D92B9" BorderStyle="None" />
            <AlternatingRowStyle BackColor="#AAAAAA" />
        </asp:GridView>

<input type="image" src="images/img_skillDetail.png"  />

Skill

             <asp:TextBox ID="SkillAutoComplete" runat="server" CssClass="text_input"></asp:TextBox>
             <cc1:AutoCompleteExtender ID="SkillAutoComplete_AutoCompleteExtender"
                  runat="server" DelimiterCharacters="" Enabled="True" ServicePath="getSkills.asmx" ServiceMethod="getAllSkills" MinimumPrefixLength="1"
                  TargetControlID="SkillAutoComplete">
             </cc1:AutoCompleteExtender>

Skill Detail

<asp:TextBox runat="server" class="text_input" id="txtSkillDetail"/>

        <asp:RequiredFieldValidator ID="validatorSkillDetail" runat="server" ValidationGroup="skill" ErrorMessage="*" ControlToValidate="txtSkillDetail"></asp:RequiredFieldValidator>

            <asp:ImageButton src="images/btn_Add.png" runat="server" ID="btnAddSkill" CausesValidation="True" ValidationGroup="skill" onclick="btnAddSkill_Click"/>
            <asp:ImageButton src="images/btnReset.png" runat="server" ID="btnResetSkill" CausesValidation="False" onclick="btnResetSkill_Click"/>

    <asp:GridView ID="grdSkill" runat="server" AutoGenerateColumns="False" Width="798px"
            AllowPaging="True"
        onpageindexchanging="grdSkill_PageIndexChanging"
        onrowcommand="grdSkill_RowCommand"
            onrowdeleting="grdSkill_RowDeleting"
            onrowediting="grdSkill_RowEditing" Font-Bold="True"
            Font-Names="Calibri" Font-Size="Medium" ForeColor="White" PageSize="5">
            <Columns>
                <asp:BoundField HeaderText="EmployeeSkillId" DataField="EmployeeSkillId" >
                </asp:BoundField>
                <asp:BoundField DataField="SkillName" HeaderText="Skill Name" ReadOnly="True">
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Skill Detail" DataField="SkillDetail"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="images/updateIcon.png" CausesValidation="false" CommandName="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeSkillId") %>'/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="images/deleteIcon.png" CommandName="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeSkillId") %>' OnClientClick="return confirm('Are you sure you want to delete this record...');"/>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <HeaderStyle BackColor="#5D92B9" BorderStyle="None" />
            <AlternatingRowStyle BackColor="#AAAAAA" />
        </asp:GridView>

<input type="image" src="images/img_qualificationDetail.png"  />

Course

<asp:DropDownList runat="server" class="text_input" id="ddlCourse"/>

Institution

<asp:TextBox runat="server" class="text_input" id="txtInstitution"/>

        <asp:RequiredFieldValidator ID="validatorInsitution" runat="server" ValidationGroup="course" ErrorMessage="*" ControlToValidate="txtInstitution"></asp:RequiredFieldValidator>

Duration

<asp:TextBox runat="server" class="text_input" id="txtCourseDuration"/>

        <asp:RequiredFieldValidator ID="validatorDuration" runat="server" ValidationGroup="course" ErrorMessage="*" ControlToValidate="txtCourseDuration"></asp:RequiredFieldValidator>

Passing Year

             <asp:TextBox ID="calPassingYear1" runat="server" CssClass="text_input"></asp:TextBox>

Marks/Percentage/GPA

<asp:TextBox runat="server" class="text_input" id="txtMarksPercentage"/>

        <asp:RequiredFieldValidator ID="validatorMarks" runat="server" ValidationGroup="course" ErrorMessage="*" ControlToValidate="txtMarksPercentage"></asp:RequiredFieldValidator>

        <asp:ImageButton src="images/btn_Add.png" runat="server" ID="btnAddCourse" CausesValidation="True" onclick="btnAddCourse_Click" ValidationGroup="course"/>
        <asp:ImageButton src="images/btnReset.png" runat="server" ID="btnResetCourse" CausesValidation="False" onclick="btnResetCourse_Click" />

    <asp:GridView ID="grdCourse" runat="server" AutoGenerateColumns="False" Width="798px"
            AllowPaging="True"
        onpageindexchanging="grdCourse_PageIndexChanging"
        onrowcommand="grdCourse_RowCommand"
            onrowdeleting="grdCourse_RowDeleting"
            onrowediting="grdCourse_RowEditing" Font-Bold="True"
            Font-Names="Calibri" Font-Size="Medium" ForeColor="White" PageSize="5">
            <Columns>
                <asp:BoundField DataField="EmployeeQualificationId"
                    HeaderText="EmployeeQualificationId" />
                <asp:BoundField HeaderText="Course" DataField="CourseTitle" ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Institution" DataField="InstitutionName"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Duration" DataField="Duration"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Passing Year" DataField="YearOfPassing"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Marks/Percentage/GPA" DataField="MarksPercentage"
                    ReadOnly="True" >
                    <ItemStyle Font-Names="Calibri,Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="Small" ForeColor="#3F4A53" />
                </asp:BoundField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="images/updateIcon.png" CausesValidation="false" CommandName="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeQualificationId") %>'/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="images/deleteIcon.png" CommandName="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeQualificationId") %>' OnClientClick="return confirm('Are you sure you want to delete this record...');"/>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <HeaderStyle BackColor="#5D92B9" BorderStyle="None" />
            <AlternatingRowStyle BackColor="#AAAAAA" />
        </asp:GridView>

    </ContentTemplate>
      </asp:UpdatePanel>

       <asp:ImageButton ID="btnSubmit" AlternateText="submit button" runat="server" src="images/btn_Submit.png" onclick="btnSubmit_Click"/>

</asp:Content>

For Example:

When I was trying to add some ASP.NET server side controls like <asp:testBox id="txtBox" runat="server"/> they were not accessible in the code behind.:

Error: txtBox is not defined in the current Context ...

What am I doing wrong?

ContentLicense: CC BY-SA 3.0


问:
List properties of my model are not being passed to the View from the Controller
I'm new to ASP.NET Core MVC, but I'm not new to ASP.NET Core (Web Apis, Function Apps, etc). I need a little help with a problem I'm having.

I have a model that looks something like this:

```<code>public class Character
{
    public string Id { get; set; } = default!;
    [Required]
    public string Name { get; set; } = default!;
    ...
    public List<Skill> Skills { get; set; } = new();
 }
</code>```

And I have a controller endpoint that looks something like this:

```<code>    [HttpGet("traits")]
    public async Task<IActionResult> Traits( Character character )
    {
        Character character = await _apiClient.GetDefaultCharacter(character.GameSystem);
        ViewBag.TraitLevels = await _apiClient.GetTraitLevels();
        return View( character );
    }
</code>```

My View has this:

```<code>@{
Character character = ViewData.Model;
...
</code>```

What happens is that character has all of its properties set to their values, except Skills. That has an empty list. Not null, but empty. It was full of values in the controller right before I pass it to View(). But as soon as the flow enters the View, Skills is emptied.

I need to have that data to allow the user to set them.

Is there something I'm doing wrong here? Or something I forgot?

Thank you.

答:
I solved it, but thanks to Caius Jard for pointing me in the right direction.

The problem was this:

```<code>return View( character );
</code>```

Apparently, ASP.NET doesn't like this, even though I saw it in a tutorial. When I did this instead, it worked:

```<code>        ViewData.Model = character;
        return View();
</code>```

This makes sense to me. Build your ViewData and then call the view like normal.

Body:
I'm new to ASP.NET Core MVC, but I'm not new to ASP.NET Core (Web Apis, Function Apps, etc). I need a little help with a problem I'm having.

I have a model that looks something like this:

public class Character
{
    public string Id { get; set; } = default!;
    [Required]
    public string Name { get; set; } = default!;
    ...
    public List<Skill> Skills { get; set; } = new();
 }

And I have a controller endpoint that looks something like this:

    [HttpGet("traits")]
    public async Task<IActionResult> Traits( Character character )
    {
        Character character = await _apiClient.GetDefaultCharacter(character.GameSystem);
        ViewBag.TraitLevels = await _apiClient.GetTraitLevels();
        return View( character );
    }

My View has this:

@{
Character character = ViewData.Model;
...

What happens is that character has all of its properties set to their values, except Skills. That has an empty list. Not null, but empty. It was full of values in the controller right before I pass it to View(). But as soon as the flow enters the View, Skills is emptied.

I need to have that data to allow the user to set them.

Is there something I'm doing wrong here? Or something I forgot?

Thank you.

Body:
I solved it, but thanks to Caius Jard for pointing me in the right direction.

The problem was this:

return View( character );

Apparently, ASP.NET doesn't like this, even though I saw it in a tutorial. When I did this instead, it worked:

        ViewData.Model = character;
        return View();

This makes sense to me. Build your ViewData and then call the view like normal.


问:
Run web developer console in windows terminal
Is there any way to run the scripts which we run in the Developer console of Chrome or Firefox on Windows Terminal or CMD?

I want to run a Javascript code on every link I provide as input.

答: For that you need to use Nodejs and libraries such as cheerio, puppeteer or selenium, ...</p>


问:
Data not available outside of onBeforeMount - Composition API / Vue 3
In the single code component, I have the following script:

```<code><script setup lang="ts">
import ApiService from '../service/api'
import { reactive, onBeforeMount } from 'vue'

let pokemons = reactive([])

onBeforeMount(async ()=> {
  const response = await ApiService.getAll()
  pokemons = response.data.results
  return pokemons
})
</script>
</code>```

Pokemons inside the OnBeforeMount exist, but not outside of it.

Any tips?

答:
onBeforeMount's callback function does not require a return value

reactive is meant to be used as a proxy to a ref value to watch all of the ref's nested properties.

<template>

{{ p.name }}

</template>

```

Body:
In the single code component, I have the following script:

Pokemons inside the OnBeforeMount exist, but not outside of it.

Any tips?

Body:
onBeforeMount's callback function does not require a return value

reactive is meant to be used as a proxy to a ref value to watch all of the ref's nested properties.

<template>
<ul>
  <li v-for="p in pokemons" :key="p.id">{{ p.name }}</li>
</ul>
</template>

<script setup lang="ts">
import ApiService from '../service/api'
import { reactive, onBeforeMount, ref } from 'vue'

const allPokemon = ref([])
const pokemons = reactive(allPokemon)

onBeforeMount(async ()=> {
  const response = await ApiService.getAll()
  allPokemon.value = response.data.results
})
</script>


问:
How to alias a prototype function using es6 syntax
The requirement is to have an alias to a prototype function.

Currently I'm doing this, which is adding an additional function and execution context, when called, as opposed to just a reference:

```<code>class X {
  x() {
    // stuff
  }

  y() {
    this.x();
  }
}
</code>```

Because I don't know how to do this, in es5:

```<code>function X() {

}
X.prototype.x = function () {
  // stuff
}
X.prototype.y = X.prototype.x;
</code>```

Is it possible?

答:
There are multiple ways to do this. The easiest is doing just the same as without class syntax:

```<code>X.prototype.y = X.prototype.x;
</code>```

If you insist on class syntax, ES2022 will have static blocks:

```<code>class X {
    …
    static {
        // notice unlike a method definition, this creates an enumerable property
        this.prototype.y = this.prototype.x;
    }
}
</code>```

If you need to limit yourself to ES2015, you can still provide the x method as y in various ways:

```<code>class X {
    …
    constructor() {
        // notice this creates an own, enumerable property
        this.y = this.x;
    }
}
</code>```

```<code>class X {
    …
    // notice this prevents assignments to `.y`
    get y() {
        return this.x;
    }
}
</code>```

Body:
The requirement is to have an alias to a prototype function.

Currently I'm doing this, which is adding an additional function and execution context, when called, as opposed to just a reference:

class X {
  x() {
    // stuff
  }

  y() {
    this.x();
  }
}

Because I don't know how to do this, in es5:

function X() {

}
X.prototype.x = function () {
  // stuff
}
X.prototype.y = X.prototype.x;

Is it possible?

Body:
There are multiple ways to do this. The easiest is doing just the same as without class syntax:

X.prototype.y = X.prototype.x;

If you insist on class syntax, ES2022 will have static blocks:

class X {
    …
    static {
        // notice unlike a method definition, this creates an enumerable property
        this.prototype.y = this.prototype.x;
    }
}

If you need to limit yourself to ES2015, you can still provide the x method as y in various ways:

class X {
    …
    constructor() {
        // notice this creates an own, enumerable property
        this.y = this.x;
    }
}

class X {
    …
    // notice this prevents assignments to `.y`
    get y() {
        return this.x;
    }
}


答:
So, creating the data:

```<code>CREATE TABLE #t (id int, title nvarchar(5), tags nvarchar(3));

INSERT INTO #t (id,title,tags)
VALUES
(1,'P1583','2,5'),
(2,'P1234','1,3'),
(3,'P1456','1');

CREATE TABLE #tag (id int, title nvarchar(10));

INSERT INTO #tag (id,title)
VALUES
(1,'Pants'),
(2,'Shorts'),
(3,'Shirts'),
(4,'Tshirts'),
(5,'Skirts');
</code>```

And using STRING_SPLIT and CROSS APPLY gives us:

```<code>SELECT #t.id, #t.title, #t.tags, tags.value, #tag.title
FROM #t
CROSS APPLY STRING_SPLIT(#t.tags,',') tags
INNER JOIN #tag ON tags.value = #tag.id;
</code>```

id
title
tags
value
title

1
P1583
2,5
2
Shorts

1
P1583
2,5
5
Skirts

2
P1234
1,3
1
Pants

2
P1234
1,3
3
Shirts

3
P1456
1
1
Pants

From there you just STRING_AGG back together:

```<code>WITH exp
AS (
SELECT #t.id, #t.title, #t.tags, tags.value, #tag.title AS tag_title
FROM #t
CROSS APPLY STRING_SPLIT(#t.tags,',') tags
INNER JOIN #tag ON tags.value = #tag.id
)
SELECT id, title, STRING_AGG(tag_title,',') WITHIN GROUP (ORDER BY tag_title) AS tag_titles
FROM exp
GROUP BY id, title;
</code>```

Title: Query result from array string with numbers to array string text?

Body:
So, creating the data:

CREATE TABLE #t (id int, title nvarchar(5), tags nvarchar(3));

INSERT INTO #t (id,title,tags)
VALUES
(1,'P1583','2,5'),
(2,'P1234','1,3'),
(3,'P1456','1');

CREATE TABLE #tag (id int, title nvarchar(10));

INSERT INTO #tag (id,title)
VALUES
(1,'Pants'),
(2,'Shorts'),
(3,'Shirts'),
(4,'Tshirts'),
(5,'Skirts');

And using STRING_SPLIT and CROSS APPLY gives us:

SELECT #t.id, #t.title, #t.tags, tags.value, #tag.title
FROM #t
CROSS APPLY STRING_SPLIT(#t.tags,',') tags
INNER JOIN #tag ON tags.value = #tag.id;

id
title
tags
value
title

1
P1583
2,5
2
Shorts

1
P1583
2,5
5
Skirts

2
P1234
1,3
1
Pants

2
P1234
1,3
3
Shirts

3
P1456
1
1
Pants

From there you just STRING_AGG back together:

WITH exp
AS (
SELECT #t.id, #t.title, #t.tags, tags.value, #tag.title AS tag_title
FROM #t
CROSS APPLY STRING_SPLIT(#t.tags,',') tags
INNER JOIN #tag ON tags.value = #tag.id
)
SELECT id, title, STRING_AGG(tag_title,',') WITHIN GROUP (ORDER BY tag_title) AS tag_titles
FROM exp
GROUP BY id, title;


问:
PHP preg_replace backreference causing undefined constant notice
I'm trying to use NameCase a php class on code.google.com.  When I run it I get this notice and I don't understand why.

PHP Notice:  Use of undefined constant Mc - assumed 'Mc' in
  namecase.php(54) : regexp code on line 1

```<code>53   if( preg_match('/\bMac[A-Za-z]{2,}[^aciozj]\b/', $str) || preg_match('/\bMc/', $str) ) {
54     $str = preg_replace("/\b(Ma?c)([A-Za-z]+)/e", "$1.ucfirst('\\2')", $str);
55     // Now correct for "Mac" exceptions
56     $str = preg_replace('/\bMacEvicius/','Macevicius', $str); // Lithuanian
57     $str = preg_replace('/\bMacHado/',   'Machado', $str);    // Portuguese
58     $str = preg_replace('/\bMacHar/',    'Machar', $str);
59     ...
</code>```

Is there anything that can be done to correct the code so it doesn't produce the notice.

Thanks

答:
You need to quote the $1 in your replacement, e.g. "'$1'.ucfirst('\\2')" or better yet, use preg_replace_callback. In PHP 5.3+ you can pass it a closure, e.g:

```<code>$str = preg_replace_callback(
    "/\b(Ma?c)([A-Za-z]+)/",
    function($m) { return $m[1] . ucfirst($m[2]); },
    $str
);
</code>```

Body:
I'm trying to use NameCase a php class on code.google.com.  When I run it I get this notice and I don't understand why.

PHP Notice:  Use of undefined constant Mc - assumed 'Mc' in
  namecase.php(54) : regexp code on line 1

53   if( preg_match('/\bMac[A-Za-z]{2,}[^aciozj]\b/', $str) || preg_match('/\bMc/', $str) ) {
54     $str = preg_replace("/\b(Ma?c)([A-Za-z]+)/e", "$1.ucfirst('\\2')", $str);
55     // Now correct for "Mac" exceptions
56     $str = preg_replace('/\bMacEvicius/','Macevicius', $str); // Lithuanian
57     $str = preg_replace('/\bMacHado/',   'Machado', $str);    // Portuguese
58     $str = preg_replace('/\bMacHar/',    'Machar', $str);
59     ...

Is there anything that can be done to correct the code so it doesn't produce the notice.

Thanks

Body:
You need to quote the $1 in your replacement, e.g. "'$1'.ucfirst('\\2')" or better yet, use preg_replace_callback. In PHP 5.3+ you can pass it a closure, e.g:

$str = preg_replace_callback(
    "/\b(Ma?c)([A-Za-z]+)/",
    function($m) { return $m[1] . ucfirst($m[2]); },
    $str
);


问:
Compare two dataframes after group by in pandas
I have the dataframe df1 as

```<code>  Userid        timestamp      pnl_of_fills variation
    111       1.643955e+09         20.00       bad
    122       1.643955e+09          2.67      good
    221       1.643955e+09          3.33      good
    2735      1.643955e+09          6.60      good
    31124243  1.643955e+09         40.00       bad
</code>```

which was created with groupby Userid in pandas dataframe.

and df2 as

```<code>   Userid

0    111
1    122
2    221
3    2735
4    111
</code>```

I need new dataframe with combine df1 and df2 as df3

df3 like

```<code>   Userid  pnl_of_fills  Variation

0    111    20.00         bad
1    122    2.67         good
2    221    3.33         good
3    2735    6.60        good
4.   111    20.00         bad
</code>```

Have tried multiple approaches and didnt find anything useful.

Basically for every value of df2 column, the df1 values needs to be updated.

答:
Suppose your 2 dataframes:

```<code>>>> df1
             timestamp  pnl_of_fills variation
Userid
111       1.643955e+09         20.00       bad
122       1.643955e+09          2.67      good
221       1.643955e+09          3.33      good
2735      1.643955e+09          6.60      good
31124243  1.643955e+09         40.00       bad

>>> df2
   Userid  Dummy
0     111     11
1     122     21
2     221     31
3    2735     41
4     111     51
</code>```

You want to merge them on Userid: the problem here is for the first dataframe, Userid is the index rather than for the second Userid is a column so you need some extra options to use with merge:

```<code># Merge with index of df1 and column on df2
>>> df1.merge(df2, left_index=True, right_on='Userid')
      timestamp  pnl_of_fills variation  Userid  Dummy
0  1.643955e+09         20.00       bad     111     11
4  1.643955e+09         20.00       bad     111     51
1  1.643955e+09          2.67      good     122     21
2  1.643955e+09          3.33      good     221     31
3  1.643955e+09          6.60      good    2735     41

# Merge both on columns because you reset index of df1
>>> df1.reset_index().merge(df2, on='Userid')
      timestamp  pnl_of_fills variation  Userid  Dummy
0  1.643955e+09         20.00       bad     111     11
4  1.643955e+09         20.00       bad     111     51
1  1.643955e+09          2.67      good     122     21
2  1.643955e+09          3.33      good     221     31
3  1.643955e+09          6.60      good    2735     41

# Light merge with join based on index of both dataframes
>>> df1.join(df2.set_index('Userid'))
             timestamp  pnl_of_fills variation  Dummy
Userid
111       1.643955e+09         20.00       bad   11.0
111       1.643955e+09         20.00       bad   51.0
122       1.643955e+09          2.67      good   21.0
221       1.643955e+09          3.33      good   31.0
2735      1.643955e+09          6.60      good   41.0
31124243  1.643955e+09         40.00       bad    NaN
</code>```

You can get more information about merge: Pandas Merging 101

Body:
I have the dataframe df1 as

  Userid        timestamp      pnl_of_fills variation
    111       1.643955e+09         20.00       bad
    122       1.643955e+09          2.67      good
    221       1.643955e+09          3.33      good
    2735      1.643955e+09          6.60      good
    31124243  1.643955e+09         40.00       bad

which was created with groupby Userid in pandas dataframe.

and df2 as

   Userid

0    111
1    122
2    221
3    2735
4    111

I need new dataframe with combine df1 and df2 as df3

df3 like

   Userid  pnl_of_fills  Variation

0    111    20.00         bad
1    122    2.67         good
2    221    3.33         good
3    2735    6.60        good
4.   111    20.00         bad

Have tried multiple approaches and didnt find anything useful.

Basically for every value of df2 column, the df1 values needs to be updated.

Body:
Suppose your 2 dataframes:

>>> df1
             timestamp  pnl_of_fills variation
Userid
111       1.643955e+09         20.00       bad
122       1.643955e+09          2.67      good
221       1.643955e+09          3.33      good
2735      1.643955e+09          6.60      good
31124243  1.643955e+09         40.00       bad

>>> df2
   Userid  Dummy
0     111     11
1     122     21
2     221     31
3    2735     41
4     111     51

You want to merge them on Userid: the problem here is for the first dataframe, Userid is the index rather than for the second Userid is a column so you need some extra options to use with merge:

# Merge with index of df1 and column on df2
>>> df1.merge(df2, left_index=True, right_on='Userid')
      timestamp  pnl_of_fills variation  Userid  Dummy
0  1.643955e+09         20.00       bad     111     11
4  1.643955e+09         20.00       bad     111     51
1  1.643955e+09          2.67      good     122     21
2  1.643955e+09          3.33      good     221     31
3  1.643955e+09          6.60      good    2735     41

# Merge both on columns because you reset index of df1
>>> df1.reset_index().merge(df2, on='Userid')
      timestamp  pnl_of_fills variation  Userid  Dummy
0  1.643955e+09         20.00       bad     111     11
4  1.643955e+09         20.00       bad     111     51
1  1.643955e+09          2.67      good     122     21
2  1.643955e+09          3.33      good     221     31
3  1.643955e+09          6.60      good    2735     41

# Light merge with join based on index of both dataframes
>>> df1.join(df2.set_index('Userid'))
             timestamp  pnl_of_fills variation  Dummy
Userid
111       1.643955e+09         20.00       bad   11.0
111       1.643955e+09         20.00       bad   51.0
122       1.643955e+09          2.67      good   21.0
221       1.643955e+09          3.33      good   31.0
2735      1.643955e+09          6.60      good   41.0
31124243  1.643955e+09         40.00       bad    NaN

You can get more information about merge: Pandas Merging 101


答:
You can use node js its run your .js file in terminal and consoles  logs.
" node Yourfilename.js "
type this command in terminal and hit enter your file will run on terminal</p>

Title: Run web developer console in windows terminal

Body:
Is there any way to run the scripts which we run in the Developer console of Chrome or Firefox on Windows Terminal or CMD?

I want to run a Javascript code on every link I provide as input.


问:
What is the meaning of onsubmit="return false"? (JavaScript, jQuery)
I know that the onsubmit event occurs when a form is submitted.

Generally, we are calling a method on the onsubmit event, like <form action="" onsubmit="myfunction()">.

Today I saw this, "<form action="" onsubmit="return false">". How does it work? I could not understand what is the meaning of onsubmit="return false".

PS: I found this when learning Ajax. It was a tutorial which explains how to submit data to a database without refreshing the page.

答:
According to the HTML standard, onsubmit is the name of an event handler. The event handler content attribute is treated as the FunctionBody of a JavaScript function which will be used to handle the associated events. In step 5 of "The event handler processing algorithm", it says "Process return value as follows":

If event is a BeforeUnloadEvent object and event's type is beforeunload

In this case, the event handler IDL attribute's type will be OnBeforeUnloadEventHandler, so return value will have been coerced
into either null or a DOMString.

If return value is not null, then:

Set event's canceled flag.

If event's returnValue attribute's value is the empty string, then set event's returnValue attribute's value to return
value.

If special error event handling is true

If return value is true, then set event's canceled flag.

Otherwise

If return value is false, then set event's canceled flag.

So, in short, return false will cancel the event (or in this case, cancels the form submission).


问:
FindAll returns AttributeError: ResultSet object has no attribute 'findAll'
I just started learning how to scrape websites a few hours ago and it seems that I've hit a roadblock regarding "FindAll"

My code:

```<code>soup = BeautifulSoup(html_text, 'lxml')
goals = soup.findAll('tr', attrs={'style': 'background-color: #262101'})
secret_goals = goals.findAll('href').text
print(secret_goals)
</code>```

It always returns an error of:

AttributeError: ResultSet object has no attribute 'findAll'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?

Is there any solutions that I can do? Or am I doing something wrong?

答:
The findAll method returns a list of tag elements: you have to loop over them and extract what you need.

```<code>goals = soup.find_all('tr', attrs={'style': 'background-color: #262101'})
result = []
for goal in goals:
    result.append(goal.get('href'))
...
</code>```

Also, I think camel case methods are deprecated, so use snake case instead. I don't think it matters though.

Body:
I just started learning how to scrape websites a few hours ago and it seems that I've hit a roadblock regarding "FindAll"

My code:

soup = BeautifulSoup(html_text, 'lxml')
goals = soup.findAll('tr', attrs={'style': 'background-color: #262101'})
secret_goals = goals.findAll('href').text
print(secret_goals)

It always returns an error of:

AttributeError: ResultSet object has no attribute 'findAll'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?

Is there any solutions that I can do? Or am I doing something wrong?

Body:
The findAll method returns a list of tag elements: you have to loop over them and extract what you need.

goals = soup.find_all('tr', attrs={'style': 'background-color: #262101'})
result = []
for goal in goals:
    result.append(goal.get('href'))
...

Also, I think camel case methods are deprecated, so use snake case instead. I don't think it matters though.


问:
.NET Regex for SQL Server string... but not Unicode string?
I'm trying to build a .NET regex to match SQL Server constant strings... but not Unicode strings.

Here's a bit of SQL:

```<code>select * from SomeTable where SomeKey = 'abc''def' and AnotherField = n'another''value'
</code>```

Note that within a string two single quotes escapes a single quote.

The regex should match 'abc''def' but not n'another''value'.

I have a regex now that manages to locate a string, but it also matches the Unicode string (starting just after the N):

```<code>'('{2})*([^']*)('{2})*([^']*)('{2})*'
</code>```

Thanks!

答:
This pattern will do most of what you are looking to do:

```<code>(?<unicode>n)?'(?<value>(?:''|[^'])*)'
</code>```

The upside is that it should accurately match any number of escaped quotes.  (SomeKey = 'abc''''def''' will match abc''''def''.)

The downside is it also matches Unicode strings, although it captures the leading n to identify it as a Unicode string.  When you process the regular expression, you can ignore matches where the match group "unicode" was successful.

The pattern creates the following groups for each match:

```<code>unicode: Success if the string is a Unicode string, fails to match if ASCII
value: the string value.  escaped single quotes remain escaped
</code>```

If you are using .NET regular expressions, you could add (?(unicode)(?<-value>)) to the end of the pattern to suppress matching the value, although the pattern as a whole would still match.

Edit

Having thought about it some more, the following pattern should do exactly what you wanted; it will not match Unicode strings at all.  The above approach might still be more readable, however.

```<code>(?:n'(?:''|[^'])*'[^']*)*(?<!n)'(?<value>(?:''|[^'])*)'
</code>```

Body:
I'm trying to build a .NET regex to match SQL Server constant strings... but not Unicode strings.

Here's a bit of SQL:

select * from SomeTable where SomeKey = 'abc''def' and AnotherField = n'another''value'

Note that within a string two single quotes escapes a single quote.

The regex should match 'abc''def' but not n'another''value'.

I have a regex now that manages to locate a string, but it also matches the Unicode string (starting just after the N):

'('{2})*([^']*)('{2})*([^']*)('{2})*'

Thanks!

Body:
This pattern will do most of what you are looking to do:

(?<unicode>n)?'(?<value>(?:''|[^'])*)'

The upside is that it should accurately match any number of escaped quotes.  (SomeKey = 'abc''''def''' will match abc''''def''.)

The downside is it also matches Unicode strings, although it captures the leading n to identify it as a Unicode string.  When you process the regular expression, you can ignore matches where the match group "unicode" was successful.

The pattern creates the following groups for each match:

unicode: Success if the string is a Unicode string, fails to match if ASCII
value: the string value.  escaped single quotes remain escaped

If you are using .NET regular expressions, you could add (?(unicode)(?<-value>)) to the end of the pattern to suppress matching the value, although the pattern as a whole would still match.

Edit

Having thought about it some more, the following pattern should do exactly what you wanted; it will not match Unicode strings at all.  The above approach might still be more readable, however.

(?:n'(?:''|[^'])*'[^']*)*(?<!n)'(?<value>(?:''|[^'])*)'